From: Mike Bayer Date: Mon, 5 Apr 2010 21:49:58 +0000 (-0400) Subject: so here is kind of the idea. but it doesn't work like it used to. X-Git-Tag: rel_0_6_0~54 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=55382b4deac137feffc50ee541cc1e5118fa809b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git so here is kind of the idea. but it doesn't work like it used to. so I think I want to try to build a smarter "find everything without a dependency" system that is more inline with how this is running now anyway - i.e. go through the whole list, find nodes with no dependencies. maybe the original topological.sort() can do that, not sure. --- diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 9f888f8672..bb3bb4fb27 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -227,10 +227,16 @@ class UOWTransaction(object): (head, children) = topological.organize_as_tree(self.dependencies, sort) stack = [(head, children)] + head.execute(self) while stack: node, children = stack.pop() - node.execute(self) - stack += children + if children: + related = set([n[0] for n in children]) + while related: + n = related.pop() + n.execute_aggregate(self, related) + + stack += children else: for rec in sort: rec.execute(self) @@ -273,6 +279,9 @@ class PostSortRec(object): uow.postsort_actions[key] = ret = object.__new__(cls) return ret + def execute_aggregate(self, uow, recs): + self.execute(uow) + def __repr__(self): return "%s(%s)" % ( self.__class__.__name__, @@ -408,6 +417,17 @@ class SaveUpdateState(PostSortRec): uow ) + def execute_aggregate(self, uow, recs): + cls_ = self.__class__ + # TODO: have 'mapper' be present on SaveUpdateState already + mapper = self.state.manager.mapper.base_mapper + + our_recs = [r for r in recs + if r.__class__ is cls_ and + r.state.manager.mapper.base_mapper is mapper] + recs.difference_update(our_recs) + mapper._save_obj([self.state] + [r.state for r in our_recs], uow) + def __repr__(self): return "%s(%s)" % ( self.__class__.__name__,