Also switched explain over to own async framework.
This commit is contained in:
parent
4dc55288b5
commit
c551d982c6
6 changed files with 17 additions and 17 deletions
|
|
@ -51,9 +51,9 @@ namespace {
|
|||
|
||||
} // END of unnamed namespace
|
||||
|
||||
std::unique_ptr<ExplainRoot> ExplainRoot::createFromJson(Json::Value &json)
|
||||
ExplainRoot::SPtr ExplainRoot::createFromJson(Json::Value &json)
|
||||
{
|
||||
auto res = std::make_unique<ExplainRoot>();
|
||||
auto res = std::make_shared<ExplainRoot>();
|
||||
// Explain always seems to be an array with one element
|
||||
if (json.isArray()) {
|
||||
if (json.size() > 0) {
|
||||
|
|
|
|||
|
|
@ -128,7 +128,8 @@ private:
|
|||
|
||||
class ExplainRoot {
|
||||
public:
|
||||
static std::unique_ptr<ExplainRoot> createFromJson(Json::Value &json);
|
||||
using SPtr = std::shared_ptr<ExplainRoot>;
|
||||
static SPtr createFromJson(Json::Value &json);
|
||||
|
||||
ExplainTreeModelItemPtr plan;
|
||||
float planningTime = 0.f;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ private:
|
|||
std::unique_ptr<QueryExplainModel> explainModel;
|
||||
|
||||
Pgsql::Canceller queryCancel;
|
||||
std::future<std::unique_ptr<ExplainRoot>> explainFuture;
|
||||
|
||||
|
||||
struct {
|
||||
std::unique_ptr<QSocketNotifier> notifier;
|
||||
|
|
@ -74,6 +74,7 @@ private:
|
|||
|
||||
void processNotice(const PGresult *result);
|
||||
void query_ready(Pgsql::Result res);
|
||||
void explain_ready(std::shared_ptr<ExplainRoot> explain);
|
||||
private slots:
|
||||
|
||||
void startConnect();
|
||||
|
|
@ -81,7 +82,7 @@ private slots:
|
|||
void performQuery();
|
||||
void performExplain();
|
||||
void socket_activate_connect(int socket);
|
||||
void explain_ready();
|
||||
|
||||
void cancel_query();
|
||||
void receiveNotice(Pgsql::ErrorDetails notice);
|
||||
|
||||
|
|
|
|||
|
|
@ -11,8 +11,7 @@ const int c_ColumnLoops = 5;
|
|||
const int c_ColumnDetails = 6;
|
||||
const int c_NumberOfColumns = 7;
|
||||
|
||||
QueryExplainModel::QueryExplainModel(QObject *parent,
|
||||
std::unique_ptr<ExplainRoot> exp)
|
||||
QueryExplainModel::QueryExplainModel(QObject *parent, ExplainRoot::SPtr exp)
|
||||
: QAbstractItemModel(parent)
|
||||
, explain(std::move(exp))
|
||||
{}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ class QueryExplainModel : public QAbstractItemModel
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QueryExplainModel(QObject *parent, std::unique_ptr<ExplainRoot> exp);
|
||||
explicit QueryExplainModel(QObject *parent, ExplainRoot::SPtr exp);
|
||||
|
||||
QVariant data(const QModelIndex &index, int role) const override;
|
||||
|
||||
|
|
@ -27,5 +27,5 @@ public:
|
|||
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<ExplainRoot> explain;
|
||||
ExplainRoot::SPtr explain;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue