Also switched explain over to own async framework.

This commit is contained in:
Eelke Klein 2016-12-30 10:38:46 +01:00
parent 4dc55288b5
commit c551d982c6
6 changed files with 17 additions and 17 deletions

View file

@ -213,9 +213,10 @@ void MainWindow::performExplain()
QString command = "EXPLAIN (ANALYZE, VERBOSE, BUFFERS, FORMAT JSON) ";
command += ui->queryEdit->toPlainText();
explainFuture = std::async(std::launch::async, [this,command]()-> std::unique_ptr<ExplainRoot>
// explainFuture = std::async(std::launch::async, [this,command]()-> std::unique_ptr<ExplainRoot>
std::thread([this,command]()
{
std::unique_ptr<ExplainRoot> explain;
std::shared_ptr<ExplainRoot> explain;
auto res = connection->query(command);
if (res.getCols() == 1 && res.getRows() == 1) {
std::string s = res.getVal(0, 0);
@ -226,16 +227,14 @@ void MainWindow::performExplain()
explain = ExplainRoot::createFromJson(root);
}
}
QMetaObject::invokeMethod(this, "explain_ready", Qt::QueuedConnection); // queues on main thread
return explain;
});
QueueTask([this, explain]() { explain_ready(explain); });
}).detach();
}
void MainWindow::explain_ready()
void MainWindow::explain_ready(ExplainRoot::SPtr explain)
{
std::unique_ptr<ExplainRoot> explain(explainFuture.get());
if (explain) {
explainModel.reset(new QueryExplainModel(nullptr, std::move(explain)));
explainModel.reset(new QueryExplainModel(nullptr, explain));
ui->explainTreeView->setModel(explainModel.get());
ui->explainTreeView->expandAll();
ui->explainTreeView->setColumnWidth(0, 200);