Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feedback to executeSql #38870

Merged
merged 4 commits into from
Sep 21, 2020

Conversation

elpaso
Copy link
Contributor

@elpaso elpaso commented Sep 19, 2020

Fixes #38092 by adding an optional QgsFeedback argument to
the executeSql method and by implementing the PQCancel
method in the PG provider internals.

While the cancellation works well for all supported provider while
fetching results in the loop, the cancellation of a running query is now
implemented for the postgres provider connection only because the GPKG
and GDAL both rely on GDALDatasetExecuteSQL which cannot be interrupted.

This PR also introduce a few optimizations in the PG DB-Manager
code that should probably fix also other "slowness" issues that
were reported after 3.x during PG query execution.

A small UX change in the SQL dialog makes it evident to the user that
a cancellation request has been sent to the backend: the button text
is changed to "Cancelling, please wait..." so that for
provider connections that are not able to interrupt the running query
and must wait for the fetching loop to exit from the executeSql call
the user knows that something is happening and that a cancellation
request has been successfully sent.

Fixes qgis#38092 by adding an optional QgsFeedback argument to
the executeSql method and by implementing the PQCancel
method in the PG provider internals.

While the cancellation works well for all supported provider while
fetching results in the loop, the cancellation of a running query is now
implemented for the postgres provider connection only because the GPKG
and GDAL both rely on GDALDatasetExecuteSQL which cannot be interrupted.

This PR also introduce a few optimizations in the PG DB-Manager
code that should probably fix also other "slowness" issues that
were reported after 3.x during PG query execution.

A small UX change in th SQL dialog makes it evident to the user that
a cancellation request has been sent to the backend: the button text
is changed to "Cancellation requested, please wait..." so that for
provider connections that are not able to interrupt the running query
and must wait for the fetching loop to exit from the exeuteSql call
the user knows that something is happening and that a cancellation
request has been successfully sent.
@elpaso elpaso added DB Manager Relating to the DB Manager core plugin Bug Either a bug report, or a bug fix. Let's hope for the latter! labels Sep 19, 2020
@github-actions github-actions bot added this to the 3.16.0 milestone Sep 19, 2020
@@ -381,6 +381,7 @@ def updateUiWhileSqlExecution(self, status):

def executeSqlCanceled(self):
self.btnCancel.setEnabled(False)
self.btnCancel.setText(self.tr("Canceling, please wait ..."))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about just "Canceling" and leave the "please wait" bit for a tooltip? Otherwise the button will grow very large for this lengthy string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't put up an argument but here are two reasons and a half for leaving as it is:

0.5: after OSGeo/gdal#2953 the cancellation will happen so fast for GPKG/SL that most of the times nobody will notice the button change, for PG the cancellation will already be immediate after this PR

  1. there is plenty of horizontal space in that part of the dialog, at the left of the button there is a huge progress bar
  2. by changing the size and the phrasing of the button drastically we reduce the likelihood that the user misses the change

but, as I said it's not so important to me.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's let @nirvn make the call?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to "Canceling" without the please wait suffix.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 and I think we should keep the ellipsis … as an indicator that something is going on (unless we can add an animated spinner).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the spinner, I suspect the cursor is already set to spinner when we click on [ Execute SQL ]. If it's not, +1 to spinner too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the cursor shouldn't spin after a click onto "Execute SQL" if it's still possible to click on "Cancel". If any, I would suggest to add spinners and ellipseses directly onto GUI elements to put them into context.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True that.

}

// This is gross but I tried with both conn and a context QObject without success: the lambda is never called.
QMetaObject::Connection moConn;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you rename this to remove the initial "m" prefix? Its confusing as it looks like a member variable at first glance.

@m-kuhn
Copy link
Member

m-kuhn commented Sep 20, 2020

Nice!

I guess this can also be used to send back other information / warnings from the db directly to where the command was launched (e.g. db manager) instead of the global message bar / message log.

@elpaso elpaso force-pushed the bugfix-gh38092-executesql-feedback branch from 1c076f6 to 6d866e3 Compare September 21, 2020 12:02
@elpaso
Copy link
Contributor Author

elpaso commented Sep 21, 2020

@m-kuhn this PR is the GDAL part of the bugfix, we will eventually be able to use it when released OSGeo/gdal#2953 (comment)

@elpaso elpaso merged commit 1c1febc into qgis:master Sep 21, 2020
@m-kuhn
Copy link
Member

m-kuhn commented Sep 21, 2020

Thanks @elpaso good job!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! DB Manager Relating to the DB Manager core plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DB Manager "cancel" button to stop a query is not working
4 participants