On 6/26/14, 12:24 PM, Mike Bayer wrote:
>
> I'm not sure what kind of application this is but I would not be mixing
> transactional control, that is the commit/rollback, inside of a business
> method that only seeks to create some new objects.   There'd be a
> containing pattern within which store_enos_rec() is called these 20K
> times, then the commit() is called on the outside of that, or at least
> every 1000 records or so.
>
> Also, the "create if not present" pattern is often much better set up by
> preloading all the objects you'll deal with up front:
>
> existing_evs = dict(Session.query(EnosValues.enos_id, EnosValues))
> if ev_id not in existing_evs:
>     Session.add(EnosValues(...))
>
>
> If you truly need to optimize a method whose job it is to start a new
> transaction, insert a single row if not present and then commit the
> transaction fully, I'd use a core insert() construct for that.  
> Spinning up a whole unit of work in that context is overkill if
> performance is a concern.
this is something that's pretty common and i may have the opportunity
soon to come up with a helper for this case.



>
>
>

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to