[Sqlalchemy-commits] sqlalchemy: - try to make get_all_pending() a little easier to r...
Brought to you by:
zzzeek
From: <co...@sq...> - 2010-12-20 01:14:53
|
details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/ce9159b0dee3 changeset: 7169:ce9159b0dee3 user: zzzeek date: Sun Dec 19 20:13:03 2010 -0500 description: - try to make get_all_pending() a little easier to read without adding calls Subject: sqlalchemy: callcounts details: http://hg.sqlalchemy.org/sqlalchemy/sqlalchemy/rev/68dd9f882a2b changeset: 7170:68dd9f882a2b user: zzzeek date: Sun Dec 19 20:14:39 2010 -0500 description: callcounts diffstat: lib/sqlalchemy/orm/attributes.py | 64 +++++++++++++++------------------ test/aaa_profiling/test_zoomark.py | 2 +- test/aaa_profiling/test_zoomark_orm.py | 2 +- 3 files changed, 31 insertions(+), 37 deletions(-) diffs (126 lines): diff -r 5ffc707d3877 -r 68dd9f882a2b lib/sqlalchemy/orm/attributes.py --- a/lib/sqlalchemy/orm/attributes.py Sun Dec 19 19:55:55 2010 -0500 +++ b/lib/sqlalchemy/orm/attributes.py Sun Dec 19 20:14:39 2010 -0500 @@ -559,23 +559,20 @@ def get_all_pending(self, state, dict_): if self.key in dict_: current = dict_[self.key] - + if current is not None: + ret = [(instance_state(current), current)] + else: + ret = [] + if self.key in state.committed_state: original = state.committed_state[self.key] if original not in (NEVER_SET, PASSIVE_NO_RESULT, None) and \ original is not current: - if current is not None: - return [ - (instance_state(current), current), - (instance_state(original), original) - ] - else: - return [(instance_state(original), original)] - - if current is not None: - return [(instance_state(current), current)] - return [] + ret.append((instance_state(original), original)) + return ret + else: + return [] def set(self, state, dict_, value, initiator, passive=PASSIVE_OFF): """Set a value on the given InstanceState. @@ -669,29 +666,26 @@ def get_all_pending(self, state, dict_): if self.key not in dict_: return [] - else: - current = dict_[self.key] + + current = dict_[self.key] + current = getattr(current, '_sa_adapter') + + if self.key in state.committed_state: + original = state.committed_state[self.key] + if original is not NO_VALUE: + current_states = [(instance_state(c), c) for c in current] + original_states = [(instance_state(c), c) for c in original] - current = self.get_collection(state, dict_, current) + current_set = dict(current_states) + original_set = dict(original_states) + + return \ + [(s, o) for s, o in current_states if s not in original_set] + \ + [(s, o) for s, o in current_states if s in original_set] + \ + [(s, o) for s, o in original_states if s not in current_set] + + return [(instance_state(o), o) for o in current] - if self.key not in state.committed_state: - return [(instance_state(o), o) for o in current] - - original = state.committed_state[self.key] - - if original is NO_VALUE: - return [(instance_state(o), o) for o in current] - else: - current_states = [(instance_state(c), c) for c in current] - original_states = [(instance_state(c), c) for c in original] - - current_set = dict(current_states) - original_set = dict(original_states) - - return \ - [(s, o) for s, o in current_states if s not in original_set] + \ - [(s, o) for s, o in current_states if s in original_set] + \ - [(s, o) for s, o in original_states if s not in current_set] def fire_append_event(self, state, dict_, value, initiator): for fn in self.dispatch.on_append: @@ -810,7 +804,7 @@ state.modified_event(dict_, self, True, old) - old_collection = self.get_collection(state, dict_, old) + old_collection = getattr(old, '_sa_adapter') dict_[self.key] = user_data @@ -1050,7 +1044,7 @@ @classmethod def from_collection(cls, attribute, state, current): original = state.committed_state.get(attribute.key, NEVER_SET) - current = attribute.get_collection(state, state.dict, current) + current = getattr(current, '_sa_adapter') if original is NO_VALUE: return cls(list(current), (), ()) diff -r 5ffc707d3877 -r 68dd9f882a2b test/aaa_profiling/test_zoomark.py --- a/test/aaa_profiling/test_zoomark.py Sun Dec 19 19:55:55 2010 -0500 +++ b/test/aaa_profiling/test_zoomark.py Sun Dec 19 20:14:39 2010 -0500 @@ -361,7 +361,7 @@ def test_profile_1_create_tables(self): self.test_baseline_1_create_tables() - @profiling.function_call_count(5045, {'2.4': 3650}) + @profiling.function_call_count(5045, {'2.6':5371, '2.4': 3650}) def test_profile_1a_populate(self): self.test_baseline_1a_populate() diff -r 5ffc707d3877 -r 68dd9f882a2b test/aaa_profiling/test_zoomark_orm.py --- a/test/aaa_profiling/test_zoomark_orm.py Sun Dec 19 19:55:55 2010 -0500 +++ b/test/aaa_profiling/test_zoomark_orm.py Sun Dec 19 20:14:39 2010 -0500 @@ -356,7 +356,7 @@ # and this number go down slightly when using the C extensions - @profiling.function_call_count(22510, {'2.6': 24055, '2.7': 22921}) + @profiling.function_call_count(22510, {'2.6': 22775, '2.7': 22921}) def test_profile_4_expressions(self): self.test_baseline_4_expressions() |