0 Replies Latest reply on Nov 30, 2007 5:57 AM by Steffen Grimm

    suggestionbox: concept to reduce db queries?

    Steffen Grimm Newbie


      when it comes that you feed a suggestion box with data from a database (e.g. via hibernate) it comes to the following problem:

      Lets assume you have written your autocomplete() function and it loads the data via hibernate. With every keypunch the db would be queried, which is with multiple users at a time definitely too much.

      Of course there are params like requestDelay which would reduce this queries but as a matter of fact it would make more sense to keep the data you got from the first query bc it already contains the results you need to display the next times.

      So my approach was to give my managed bean session scope and change my autocomplete() function the following way: I added a List "resultList" and now, only when 2 letters are in the box a db query is made. The result of this query is saved in the resultList. Next time, if more than 2 letters are there the results will be taken out of this list, which is much faster and you only query the db once. I configured the suggestionbox with:


      to achieve that the first request (with the db query) is sent and first when its finished the following are sent (bc without the first one the others wont have data)

      Do you think this is a good idea? What are your approaches to handle suggestion boxes with data sources? I think the weak point in my strategy is, that now there are a lot more requests sent to the server and also they are not aborted anymore. If there was a possibility to only not abort the request with the db access, the performance would be better I think.

      Well I hope you can give advice and share your ideas :)

      Thanks in advance, kind regards.