Hey gang -

A feature I have procrastinated on for weeks is now complete - deferred property loading ! and as a related bonus, minimal column updates !

Deferred Property Loading
------------------------------------
deferred property loading is basically "lazy load for scalar properties". heres how it looks:

        m = mapper(Order, orders, properties={
            'description':deferred(orders.c.description)
        })

Now, when you load some Order objects in, the "description" column will not be in the select list. it will only be loaded in when you actually access it. This is a really key memory/performance feature - for examples like the "blog demo", the front page listing of posts would normally load the full row in for each entry into memory, including the "body" which could be very large, even though its never displayed. By "deferring" it you save the trouble of loading it all the time and only when its actually needed.

Minimal Column Updates
-----------------------------------
The saving of objects that results in an UPDATE statement has also been modified to only specify SET clauses for those columns that have actually changed. This keeps "deferred" columns from being loaded unnecessarily, and also keeps potentially large numbers of fields or large-sized fields from being repeatedly updated with the same data.

Deferral Groups
-----------------------
A 'group' string can be specified to group multiple properties together into a single deferred load, triggered when you first access any of the grouped properties:

        m = mapper(PressRelease, pressreleases, properties = {
                'body' : deferred(pressreleases.c.body, group='secondary'),
                'image' : deferred(pressreleases.c.image_data, 
group='secondary'),
                'credits':deferred(pressrelease.c.credit, group='secondary'),
        })

        release = m.get_by(release_id=7)

# when you access 'body', 'image', or 'credits', all three will be loaded in
        print "body: " , release.body

Deferred Options
------------------------
The "deferred" idea can also be swtiched on or off or modified with the options 'defer' and 'undefer':

        # get a copy of 'm' that loads 'description' in the main query
        m2 = m.options(undefer('description'))

        # get a copy of 'm' that defers the loading of 'data' in
        m3 = m.options(defer('data'), undefer('description'))

        # add a property to a 'deferral group'
        m4 = m.options(defer('data', group='load_info'))

        # property names can also be . separated to specify nested mappers
        dmapper = myclass.mapper.options(defer('prop1.prop2.largefield'))

Hope everyone's testing is going well.

- mike



-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
Sqlalchemy-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to