]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
more speed improvements, built hotshot prof into masseagerload test
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 May 2007 21:27:12 +0000 (21:27 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 26 May 2007 21:27:12 +0000 (21:27 +0000)
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/util.py
test/perf/masseagerload.py

index 3fe0d150e6870500613decf67acfd11c2da1e51d..5567a7824a5eb8071dc7f00a58b1a6606f040216 100644 (file)
@@ -1477,17 +1477,16 @@ class Mapper(object):
             if self.allow_null_pks:
                 # check if *all* primary key cols in the result are None - this indicates
                 # an instance of the object is not present in the row.
-                for col in self.primary_key:
-                    if row[col] is not None:
+                for x in identitykey[1]:
+                    if x is not None:
                         break
                 else:
                     return None
             else:
                 # otherwise, check if *any* primary key cols in the result are None - this indicates
                 # an instance of the object is not present in the row.
-                for col in self.primary_key:
-                    if row[col] is None:
-                        return None
+                if None in identitykey[1]:
+                    return None
 
             # plugin point
             instance = extension.create_instance(self, context, row, self.class_)
index 4fc361fbf772ce44ede2d42d5a0dd85d752058b4..02dff674be51bae2d1dd988791661d2fd0f01cb1 100644 (file)
@@ -284,9 +284,6 @@ class OrderedDict(dict):
             self._list.append(key)
         dict.__setitem__(self, key, object)
 
-    def __getitem__(self, key):
-        return dict.__getitem__(self, key)
-
 class ThreadLocal(object):
     """An object in which attribute access occurs only within the context of the current thread."""
 
@@ -420,18 +417,21 @@ class OrderedSet(Set):
     __isub__ = difference_update
 
 class UniqueAppender(object):
+    """appends items to a list such that consecutive repeats of
+    a particular item are skipped."""
+    
     def __init__(self, data):
         self.data = data
         if hasattr(data, 'append'):
             self._data_appender = data.append
         elif hasattr(data, 'add'):
             self._data_appender = data.add
-        self.set = Set()
-
+        self.__last = None
+        
     def append(self, item):
-        if item not in self.set:
-            self.set.add(item)
+        if item is not self.__last:
             self._data_appender(item)
+            self.__last = item
     
     def __iter__(self):
         return iter(self.data)
index 23b4c5ba1b78046994a2786a8f8260bffbc53df6..01aa7cf9ed0be8255fdaa9ba6eeeb88c66f06eb4 100644 (file)
@@ -5,11 +5,13 @@ import StringIO
 import testbase
 import gc
 import time
+import hotshot
+import hotshot.stats
 
 db = testbase.db
 
-NUM = 25000
-DIVISOR = 500
+NUM = 500
+DIVISOR = 50
 
 class LoadTest(AssertMixin):
     def setUpAll(self):
@@ -28,13 +30,13 @@ class LoadTest(AssertMixin):
     def setUp(self):
         clear_mappers()
         l = []
-        for x in range(1,NUM/DIVISOR):
+        for x in range(1,NUM/DIVISOR + 1):
             l.append({'item_id':x, 'value':'this is item #%d' % x})
         #print l
         items.insert().execute(*l)
-        for x in range(1, NUM/DIVISOR):
+        for x in range(1, NUM/DIVISOR + 1):
             l = []
-            for y in range(1, NUM/(NUM/DIVISOR)):
+            for y in range(1, NUM/(NUM/DIVISOR) + 1):
                 z = ((x-1) * NUM/(NUM/DIVISOR)) + y
                 l.append({'sub_id':z,'value':'this is iteim #%d' % z, 'parent_id':x})
             #print l
@@ -45,12 +47,16 @@ class LoadTest(AssertMixin):
         mapper(Item, items, properties={'subs':relation(SubItem, lazy=False)})
         mapper(SubItem, subitems)
         sess = create_session()
-        now = time.time()
+        prof = hotshot.Profile("masseagerload.prof")
+        prof.start()
         query = sess.query(Item)
         l = query.select()
         print "loaded ", len(l), " items each with ", len(l[0].subs), "subitems"
-        total = time.time() -now
-        print "total time ", total
+        prof.stop()
+        prof.close()
+        stats = hotshot.stats.load("masseagerload.prof")
+        stats.sort_stats('time', 'calls')
+        stats.print_stats()
         
 if __name__ == "__main__":
     testbase.main()