From: Mike Bayer Date: Wed, 7 Apr 2010 18:23:06 +0000 (-0400) Subject: holy callcount batman X-Git-Tag: rel_0_6_0~40^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=e9d01db09b5084280660766fded8baf040b7c426;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git holy callcount batman --- diff --git a/CHANGES b/CHANGES index 550428a444..c556ce6c6d 100644 --- a/CHANGES +++ b/CHANGES @@ -50,6 +50,12 @@ CHANGES cursor.rowcount at all, a warning is emitted the same as with saves. [ticket:1761] + - The ORM now short-term caches the "compiled" form of + insert() and update() constructs when flushing lists of + objects of all the same class, thereby avoiding redundant + compilation per individual INSERT/UPDATE within an + individual flush() call. + - internal getattr(), setattr(), getcommitted() methods on ColumnProperty, CompositeProperty, RelationshipProperty have been underscored, signature has changed. diff --git a/lib/sqlalchemy/orm/mapper.py b/lib/sqlalchemy/orm/mapper.py index b57400c097..6d0a51a526 100644 --- a/lib/sqlalchemy/orm/mapper.py +++ b/lib/sqlalchemy/orm/mapper.py @@ -1451,6 +1451,7 @@ class Mapper(object): update.append((state, state_dict, params, mapper, connection, value_params)) + if update: mapper = table_to_mapper[table] clause = sql.and_() @@ -1470,9 +1471,21 @@ class Mapper(object): statement = table.update(clause) + if len(update) > 1: + compiled_cache = {} + else: + compiled_cache = None + rows = 0 for state, state_dict, params, mapper, connection, value_params in update: - c = connection.execute(statement.values(value_params), params) + if not value_params and compiled_cache is not None: + c = connection.\ + execution_options( + compiled_cache=compiled_cache).\ + execute(statement, params) + else: + c = connection.execute(statement.values(value_params), params) + mapper._postfetch(uowtransaction, table, state, state_dict, c, c.last_updated_params(), value_params) @@ -1493,8 +1506,19 @@ class Mapper(object): if insert: statement = table.insert() + if len(insert) > 1: + compiled_cache = {} + else: + compiled_cache = None + for state, state_dict, params, mapper, connection, value_params in insert: - c = connection.execute(statement.values(value_params), params) + if not value_params and compiled_cache is not None: + c = connection.\ + execution_options( + compiled_cache=compiled_cache).\ + execute(statement, params) + else: + c = connection.execute(statement.values(value_params), params) primary_key = c.inserted_primary_key if primary_key is not None: diff --git a/test/aaa_profiling/test_zoomark_orm.py b/test/aaa_profiling/test_zoomark_orm.py index 5b962b695f..9b31d82f56 100644 --- a/test/aaa_profiling/test_zoomark_orm.py +++ b/test/aaa_profiling/test_zoomark_orm.py @@ -291,7 +291,7 @@ class ZooMarkTest(TestBase): def test_profile_1_create_tables(self): self.test_baseline_1_create_tables() - @profiling.function_call_count(12178, {'2.4':12178}) + @profiling.function_call_count(9225) def test_profile_1a_populate(self): self.test_baseline_1a_populate()