From: Mike Bayer Date: Fri, 9 Apr 2010 22:17:06 +0000 (-0400) Subject: attempt to reduce redundant calc of pk_switched X-Git-Tag: rel_0_6_0~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=fe09dbf36e9300210d152a6c79e8d44f54c4c238;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git attempt to reduce redundant calc of pk_switched --- diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index bab3cb936b..dd595a052d 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -714,10 +714,9 @@ class DetectKeySwitch(DependencyProcessor): def prop_has_changes(self, uow, states, isdelete): if not isdelete and self.passive_updates: - for s in states: - if self._pks_changed(uow, s): - return True - + d = self._key_switchers(uow, states) + return bool(d) + return False def process_deletes(self, uowcommit, states): @@ -731,8 +730,23 @@ class DetectKeySwitch(DependencyProcessor): assert self.passive_updates self._process_key_switches(states, uowcommit) + def _key_switchers(self, uow, states): + if ('pk_switchers', self) in uow.attributes: + switched, notswitched = uow.attributes[('pk_switchers', self)] + else: + uow.attributes[('pk_switchers', self)] = (switched, notswitched) = (set(), set()) + + allstates = switched.union(notswitched) + for s in states: + if s not in allstates: + if self._pks_changed(uow, s): + switched.add(s) + else: + notswitched.add(s) + return switched + def _process_key_switches(self, deplist, uowcommit): - switchers = set(s for s in deplist if self._pks_changed(uowcommit, s)) + switchers = self._key_switchers(uowcommit, deplist) if switchers: # if primary key values have actually changed somewhere, perform # a linear search through the UOW in search of a parent.