tags:

views:

39

answers:

3

Hi,

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

A: 

I am not an expert, but you can store the time he last filed the query in his session. If the same user file another query with 20 secs, just ignore it.

It's not really a brute force way though.

Winston Chen
A: 
  • 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.

Will Hartung
+2  A: 

First step would be to optimize that query, 20 seconds is way too long for most queries. Users won't generally tolerate that kind of poor performance.

HLGEM