SQLObject optimizations

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

SQLObject optimizations

Don Hopkins
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:

http://www.donhopkins.com/drupal/?q=node/43
http://www.donhopkins.com/drupal/?q=node/44

        -Don

    # Use lazyColumns=True so it only selects id's that match the SQL
query,
    # 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
objects,
    # and the byte size of the result.
    for id in ids:
        object = GetSimsObjectById(id)
        if objectcache.has_key(id):
            out2.write(
                '<object objectid="' + str(object.id) + '"/>')
            referenceCount += 1
            if referenceCount >= referenceLimit:
                break
        else:
            WriteObjectSummary(object, out2)
            objectcache[id] = True
            manifestCount += 1
            if manifestCount >= manifestLimit:
                break

        anyCount += 1
        if anyCount >= anyLimit:
            break

        if out2.len >= sizeLimit:
            break



_______________________________________________
Baypiggies mailing list
[hidden email]
http://www.baypiggies.net/cgi-bin/mailman/listinfo/baypiggies