Here's how made SQLObject's select search on arbitrary sql expressions
much faster, by fetching just the object id's, instead of each entire
row (via lazyColumns=True. I grab the object ids out of the cursor via
fetchall (is there a better more portable way to do that?). Then I look
up the object id in the cache. I am keeping my own cache of the objects
I've already downloaded to the Laszlo client in the session, and sending
references instead of downloading them again. If they're not in the
user's session cache, then GetSimsObjectById calls SimsObject.get(id),
possibly fetching it from SQLObject's cache.
I read over the SQLObject code guts and hacked this so it worked -- I'm
not sure this is the way it's actually supposed to be used or
particularly portable, but it's a lot faster than just calling
SimsObject.select(sql) directly, because that fetches all the rows
again, even if they're already cached.
Here are some screen snapshots of the Sims Content Catalog application
written in OpenLaszlo, whose server is written in Python with SQLObject:
# Use lazyColumns=True so it only selects id's that match the SQL
# instead of loading all columns from the database.
objects = SimsObject.select(sql, lazyColumns=True)
total = objects.count()
# Extract the object ids from the query result,
# using the low level cursor.
objects = objects[start : start + anyLimit]
ids = iter(objects).cursor.fetchall()
ids = [id for (id,) in ids]
# Write out references to objects already in the client cache,
# or the full object summary for objects the client hasn't seen yet.
# Enforce limits on the number of referenced objects, manifest
# and the byte size of the result.
for id in ids:
object = GetSimsObjectById(id)
'<object objectid="' + str(object.id) + '"/>')
referenceCount += 1
if referenceCount >= referenceLimit:
objectcache[id] = True
manifestCount += 1
if manifestCount >= manifestLimit: