Say we have a database query that takes 20seconds to run (the user runs it by clicking a button on HTML page in a browser).
The user gets impatient and only after 10seconds he refreshes his browser, only to run a new query.
How do I stop the first running database query (or prevent the second one from running)?
Thanks
If this is using Ajax, disable the
button that starts the query until
after the query is finished.
When the use makes the request, set a
flag in the user session, and then
start the query on a separate thread.
If they try to submit it again, check
the flag, and simply ignore the
request. When the query finishes,
reset the flag. While the query is
running, the browser can poll the
server waiting for the results.