> On Dec 2, 2014, at 4:32 PM, Laurence Rowe <[email protected]> wrote: > > I've been experimenting with precompiled queries in my app using the second > recipe on > https://bitbucket.org/zzzeek/sqlalchemy/wiki/UsageRecipes/BakedQuery. I'm > seeing a big speed up, with pages 30-40% faster (my application has graph > structured content so some pages require ~100 items.) But I'm also seeing an > increase in the number of db requests as I've had to switch from: > > model = session.query(Resource).get(uuid) > > to: > > @precompiled_query_builder(DBSession) > def _get_by_uuid_query(): > session = DBSession() > return session.query(Resource).filter(Resource.rid == > bindparam('rid')) > ... > model = _get_by_uuid_query().params(rid=uuid).one() > > > I think this is due to the identity map not being used. Is there a way to > precompile queries for .get() and have the best of both?
the most mature version of “bake” is the one being added to 1.0, which you can see at https://bitbucket.org/zzzeek/sqlalchemy/commits/branch/ticket_3054 <https://bitbucket.org/zzzeek/sqlalchemy/commits/branch/ticket_3054> (do a git diff master…ticket_3054 to see the whole thing at once). This one will be integrated into lazy loading, which means a solution for get() has been devised, though it is not made public as of yet, the loading._load_on_ident_from_baked() function. I haven’t looked at this branch in a few months but I think it would be feasible for BakedQuery.get() to wire into this. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.
