]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
added conditional flag to debug log statements in mapper so that string formats dont...
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Dec 2006 18:41:33 +0000 (18:41 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 1 Dec 2006 18:41:33 +0000 (18:41 +0000)
updated massload test to work with 0.3

lib/sqlalchemy/orm/mapper.py
test/orm/unitofwork.py
test/perf/massload.py

index 5fc986d6befafce5197252dbc94cf1476a06f5fa..fd36700e6ff07918d367d7a7cb563a394a2cf86d 100644 (file)
@@ -204,6 +204,7 @@ class Mapper(object):
         # mapper.
         self._compile_class()
 
+        self.__should_log_debug = logging.is_debug_enabled(self.logger)
         self.__log("constructed")
         
         # uncomment to compile at construction time (the old way)
@@ -806,7 +807,8 @@ class Mapper(object):
         ordering among a polymorphic chain of instances. Therefore save_obj is typically 
         called only on a "base mapper", or a mapper which does not inherit from any other mapper."""
         
-        self.__log_debug("save_obj() start, " + (single and "non-batched" or "batched"))
+        if self.__should_log_debug:
+            self.__log_debug("save_obj() start, " + (single and "non-batched" or "batched"))
         
         # if batch=false, call save_obj separately for each object
         if not single and not self.batch:
@@ -836,7 +838,8 @@ class Mapper(object):
                 existing = uowtransaction.uow.identity_map[instance_key]
                 if not uowtransaction.is_deleted(existing):
                     raise exceptions.FlushError("New instance %s with identity key %s conflicts with persistent instance %s" % (mapperutil.instance_str(obj), str(instance_key), mapperutil.instance_str(existing)))
-                self.__log_debug("detected row switch for identity %s.  will update %s, remove %s from transaction" % (instance_key, mapperutil.instance_str(obj), mapperutil.instance_str(existing)))
+                if self.__should_log_debug:
+                    self.__log_debug("detected row switch for identity %s.  will update %s, remove %s from transaction" % (instance_key, mapperutil.instance_str(obj), mapperutil.instance_str(existing)))
                 uowtransaction.unregister_object(existing)
             
         inserted_objects = util.Set()
@@ -857,7 +860,8 @@ class Mapper(object):
                 if table not in mapper.tables or not mapper._has_pks(table):
                     continue
                 instance_key = mapper.instance_key(obj)
-                self.__log_debug("save_obj() table '%s' instance %s identity %s" % (table.name, mapperutil.instance_str(obj), str(instance_key)))
+                if self.__should_log_debug:
+                    self.__log_debug("save_obj() table '%s' instance %s identity %s" % (table.name, mapperutil.instance_str(obj), str(instance_key)))
 
                 isinsert = not instance_key in uowtransaction.uow.identity_map and not postupdate and not has_identity(obj)
                 params = {}
@@ -886,7 +890,8 @@ class Mapper(object):
                                 params[col.key] = value
                     elif mapper.polymorphic_on is not None and mapper.polymorphic_on.shares_lineage(col):
                         if isinsert:
-                            self.__log_debug("Using polymorphic identity '%s' for insert column '%s'" % (mapper.polymorphic_identity, col.key))
+                            if self.__should_log_debug:
+                                self.__log_debug("Using polymorphic identity '%s' for insert column '%s'" % (mapper.polymorphic_identity, col.key))
                             value = mapper.polymorphic_identity
                             if col.default is None or value is not None:
                                 params[col.key] = value
@@ -1024,7 +1029,8 @@ class Mapper(object):
         
         this is called within the context of a UOWTransaction during a flush operation."""
 
-        self.__log_debug("delete_obj() start")
+        if self.__should_log_debug:
+            self.__log_debug("delete_obj() start")
 
         connection = uowtransaction.transaction.connection(self)
 
@@ -1141,7 +1147,8 @@ class Mapper(object):
         identitykey = self.identity_key_from_row(row)
         if context.session.has_key(identitykey):
             instance = context.session._get(identitykey)
-            self.__log_debug("_instance(): using existing instance %s identity %s" % (mapperutil.instance_str(instance), str(identitykey)))
+            if self.__should_log_debug:
+                self.__log_debug("_instance(): using existing instance %s identity %s" % (mapperutil.instance_str(instance), str(identitykey)))
             isnew = False
             if context.version_check and self.version_id_col is not None and self.get_attr_by_column(instance, self.version_id_col) != row[self.version_id_col]:
                 raise exceptions.ConcurrentModificationError("Instance '%s' version of %s does not match %s" % (instance, self.get_attr_by_column(instance, self.version_id_col), row[self.version_id_col]))
@@ -1156,7 +1163,8 @@ class Mapper(object):
                     result.append(instance)
             return instance
         else:
-            self.__log_debug("_instance(): identity key %s not in session" % str(identitykey) + repr([mapperutil.instance_str(x) for x in context.session]))
+            if self.__should_log_debug:
+                self.__log_debug("_instance(): identity key %s not in session" % str(identitykey) + repr([mapperutil.instance_str(x) for x in context.session]))
         # look in result-local identitymap for it.
         exists = context.identity_map.has_key(identitykey)      
         if not exists:
@@ -1179,7 +1187,8 @@ class Mapper(object):
             instance = self.extension.create_instance(self, context, row, self.class_)
             if instance is EXT_PASS:
                 instance = self._create_instance(context.session)
-            self.__log_debug("_instance(): created new instance %s identity %s" % (mapperutil.instance_str(instance), str(identitykey)))
+            if self.__should_log_debug:
+                self.__log_debug("_instance(): created new instance %s identity %s" % (mapperutil.instance_str(instance), str(identitykey)))
             context.identity_map[identitykey] = instance
             isnew = True
         else:
index 0034b31b18d3406169770168ed7f13d0b39a4ddb..faead64f077f98d16652bf4a0f7040bc9f13c28e 100644 (file)
@@ -845,7 +845,7 @@ class SaveTest(UnitOfWorkTest):
         """tests moving a child from one parent to the other, then deleting the first parent, properly
         updates the child with the new parent.  this tests the 'trackparent' option in the attributes module."""
         m = mapper(User, users, properties = dict(
-            addresses = relation(mapper(Address, addresses), lazy = True, private = False)
+            addresses = relation(mapper(Address, addresses), lazy = True)
         ))
         u1 = User()
         u1.user_name = 'user1'
index 480aebe718afacf182f7e4f5c6cb88844073fb5c..9cbabea17a7420b675e6317a11e9d383d8a93eef 100644 (file)
@@ -1,14 +1,15 @@
 from testbase import PersistTest, AssertMixin
 import unittest, sys, os
 from sqlalchemy import *
-import sqlalchemy.attributes as attributes
+import sqlalchemy.orm.attributes as attributes
 import StringIO
 import testbase
 import gc
+import time
 
 db = testbase.db
 
-NUM = 25000
+NUM = 2500
 
 """
 we are testing session.expunge() here, also that the attributes and unitofwork packages dont keep dereferenced
@@ -18,18 +19,14 @@ for best results, dont run with sqlite :memory: database, and keep an eye on top
 
 class LoadTest(AssertMixin):
     def setUpAll(self):
-        db.echo = False
-        global items
-        items = Table('items', db
+        global items, meta
+        meta = BoundMetaData(db)
+        items = Table('items', meta
             Column('item_id', Integer, primary_key=True),
             Column('value', String(100)))
         items.create()
-        db.echo = testbase.echo
     def tearDownAll(self):
-        db.echo = False
         items.drop()
-        items.deregister()
-        db.echo = testbase.echo
     def setUp(self):
         objectstore.clear()
         clear_mappers()
@@ -44,6 +41,7 @@ class LoadTest(AssertMixin):
             
         m = mapper(Item, items)
         sess = create_session()
+        now = time.time()
         query = sess.query(Item)
         for x in range (1,NUM/100):
             # this is not needed with cpython which clears non-circular refs immediately
@@ -61,6 +59,8 @@ class LoadTest(AssertMixin):
             #print len(objectstore.get_session().dirty)
             #print len(objectstore.get_session().identity_map)
             #objectstore.expunge(*l)
-
+        total = time.time() -now
+        print "total time ", total
+        
 if __name__ == "__main__":
     testbase.main()