views:

39

answers:

2

For Example

Let say we have 1000 products in a single category. And we would like to Filter through these products.

As we Filter through the products using json. Each time we have need run a separate query to the DB.

We were wondering if any one knows if it's possible display a preload the products table. For example preload bar: initializing search (0 - 100%)

So the whole system would only initialize once on load then we would hope the search results could then be instant.

Unfortunately tweaking customers servers isn't really an option for us, so hopefully someone here may have a better suggestion

Thanks in advance!

A: 

On the PHP end, you could preload the records into something like a memcache bucket.

I strongly doubt, though, that the problem is the database query. It's much more likely that the json request is what takes so long.

It's certainly possible to preload all the values (i.e. fetch them in one big request). You are not giving any details about your system, but it would probably simply be a big json request.

I don't see any easy way to implement a progress bar for the Ajax request. Maybe a simple "loading" animation will do as well.

You would probably have to use some sort of local storage to persist the data across pages for it to make sense. For that, see this question.

Unicron
Sorry for my delayed response, there is the issue with the fact I won't be able to use memcached, or a client-side storage (Google Gears). Do you know of another method that I can use to make relatively large queries faster? The JSON data that is produced from the result is pretty small so I don't think that is the issue.
AMW10
@AMW you should definitely find out what exactly the bottleneck is forst. The JSON data may be small but if you make a thousand single requests, the latency is going to take forever. Use a PHP profiler on the server side, and measuring response times on browser side (using Firebug). If it's server side, take a look into mySQL query caching - if you have root access to the server.
Unicron
A: 

1000 data sets isn't that much to query through, but it is a significant amount to store client side. However.. to answer your question:

Javscript can create an array of objects. Let's say

<script type="text/javascript">
var products = new Array()
products[0] = {name:'First', price:29.99};
products[1] = {name:'Second', price:29.99};
products[2] = {name:'Third', price:29.99};
</script>

... create these via php. Also instead of {...} you can create a function product(name, price) and then call products[0] = new product("first", 29.99);

When you have this set up all information is stored in the clients browser. So now you can use a search/filter via only javascript. Loading bar can be neatly done through jquery-ui. Searching involves an array loop. If you have multiple categories that you can separate before hand - you can just create different arrays, instead of storing everything in products array.

Good luck!

Mikhail
AMW10