Homepage speed up

I’ve just sped up the time to generate the homepage from 2.2 seconds to 0.1 seconds by moving a bracket once place to the right!

This is slightly simplified but my old code was something like:
results = list(Person.select(query))[:10]

Which I changed to:
results = list(Person.select(query)[:10])

In the code ‘Person’ in an SQLObject class.

The first version queries and processes the entire database and then throws away all but the first 10 items. The second version only processes the first 10 items as SQLObject will smartly replace the slice with a “LIMIT 10″ in SQL.

It’s amazing the power of a bracket!

Leave a Reply

You must be logged in to post a comment.