[storm] Lazy value loading

Pietro Abate Pietro.Abate at pps.jussieu.fr
Fri Oct 24 13:24:51 BST 2008


Wild attempt to answer your question...

Maybe you can add a __init__ method to your Book class and then build
the Book object manualy after fetching the values you are interested in
with store.find((Book.author, Book.title))

something like 

l=[]
for b in store.find((Book.author, Book.title)) :
    l.append(Book(Book.author,Book.title))

and then add a method like contents() to lazy load the contents of
your books on request ( l[i].contents() )... 

I'm sure there is a smarter way of doing this.

:)
p

On Fri, Oct 24, 2008 at 02:16:25PM +0200, Adrian Adamiak wrote:
> Hi. I've got a question about lazy value loading.
> 
> Let's say that I have an ORM mapping for table 'book':
> 
> class Book(object):
>     __storm_table__ = "book"
>     id = Int(primary=True)
>     author = Unicode()
>     title = Unicode()
>     contents = Unicode()     # this can be big
> 
> Sometimes I need to display a list of titles and authors of all books, so I use:
> 
> books = store.find(Book)
> 
> Unfortunately this produces query which loads all fields, including
> 'contents', which is unnecessary and takes a lot of time. I'd like to
> make the 'contents' field lazy, i.e.
> 
>  contents = Unicode(lazy=True)    # (in Book class definition)
> 
> so that it would load only after I access this field (i.e.
> books[0].contents). Is it possible?
> 
> Thanks,
> Adrian
> 
> PS. I know I can do store.find((Book.author, Book.title)), but it
> doesn't return Book objects, which I use later to update values.
> 
> -- 
> storm mailing list
> storm at lists.canonical.com
> Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/storm



More information about the storm mailing list