]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- significant speed improvement to ResultProxy, pre-caches
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 31 May 2007 17:17:22 +0000 (17:17 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 31 May 2007 17:17:22 +0000 (17:17 +0000)
TypeEngine dialect implementations and saves on function calls
per column.  drops the masseagerload test from 80K function calls
to 66K

CHANGES
lib/sqlalchemy/engine/base.py

diff --git a/CHANGES b/CHANGES
index f63adb7dfef61d95234292eb853faf63408f8579..b14bd7db733192271b99db881131f8ef99e41584 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -11,6 +11,9 @@
       behave more properly with regards to FROM clause #574 
     - fix to long name generation when using oid_column as an order by
       (oids used heavily in mapper queries)
+    - significant speed improvement to ResultProxy, pre-caches
+      TypeEngine dialect implementations and saves on function calls
+      per column
     - parenthesis are applied to clauses via a new _Grouping construct.
       uses operator precedence to more intelligently apply parenthesis 
       to clauses, provides cleaner nesting of clauses (doesnt mutate
index ca18d1e26b691e418665986730ee4bdf4f543d88..a59e578098e5e971a9d4722d95dacd0886364caa 100644 (file)
@@ -857,12 +857,12 @@ class ResultProxy(object):
     def __init__(self, context):
         """ResultProxy objects are constructed via the execute() method on SQLEngine."""
         self.context = context
+        self.dialect = context.dialect
         self.closed = False
         self.cursor = context.cursor
         self.__echo = logging.is_debug_enabled(context.engine.logger)
         self._init_metadata()
         
-    dialect = property(lambda s:s.context.dialect)
     rowcount = property(lambda s:s.context.get_rowcount())
     connection = property(lambda s:s.context.connection)
     
@@ -873,14 +873,17 @@ class ResultProxy(object):
         self.__props = {}
         self.__keys = []
         metadata = self.cursor.description
+
         if metadata is not None:
             for i, item in enumerate(metadata):
                 # sqlite possibly prepending table name to colnames so strip
                 colname = item[0].split('.')[-1]
                 if self.context.typemap is not None:
-                    rec = (self.context.typemap.get(colname.lower(), types.NULLTYPE), i)
+                    type = self.context.typemap.get(colname.lower(), types.NULLTYPE)
                 else:
-                    rec = (types.NULLTYPE, i)
+                    type = types.NULLTYPE
+                rec = (type, type.dialect_impl(self.dialect), i)
+
                 if rec[0] is None:
                     raise DBAPIError("None for metadata " + colname)
                 if self.__props.setdefault(colname.lower(), rec) is not rec:
@@ -989,7 +992,7 @@ class ResultProxy(object):
 
     def _get_col(self, row, key):
         rec = self._convert_key(key)
-        return rec[0].dialect_impl(self.dialect).convert_result_value(row[rec[1]], self.dialect)
+        return rec[1].convert_result_value(row[rec[2]], self.dialect)
     
     def _fetchone_impl(self):
         return self.cursor.fetchone()
@@ -1101,7 +1104,7 @@ class BufferedColumnResultProxy(ResultProxy):
     """
     def _get_col(self, row, key):
         rec = self._convert_key(key)
-        return row[rec[1]]
+        return row[rec[2]]
     
     def _process_row(self, row):
         sup = super(BufferedColumnResultProxy, self)