]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
holy callcount batman
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2010 18:23:06 +0000 (14:23 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2010 18:23:06 +0000 (14:23 -0400)
CHANGES
lib/sqlalchemy/orm/mapper.py
test/aaa_profiling/test_zoomark_orm.py

diff --git a/CHANGES b/CHANGES
index 550428a44491f2d5b902214394bc5e29f8976c8a..c556ce6c6dfafe4d0b05f4ac8469436c66638596 100644 (file)
--- 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.
index b57400c0971562a0501300beb3fb6ca547927629..6d0a51a5266e0f643768731249ed2963bc6f834d 100644 (file)
@@ -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:
index 5b962b695fbeed9d0bd41ceb38f0c621f2fce8fd..9b31d82f5689b56eb9d87ff24580e963e1fd8f40 100644 (file)
@@ -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()