summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-06-29 00:10:59 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-06-29 00:10:59 -0400
commit992e06412cf124d511d56d2741988f503f4c8085 (patch)
tree9edc61bd5124e80373046901d431f66e95a7c472 /lib/sqlalchemy
parent3be078425fdcf0d0baee01328a729efc5087a535 (diff)
downloadsqlalchemy-992e06412cf124d511d56d2741988f503f4c8085.tar.gz
- attach the ResultMetaData to the Compiled object, when we detect that
the compiled cache is used. That allows us to cache the whole metadata and save on creating it at result time, when compiled cache is used.
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/engine/result.py16
-rw-r--r--lib/sqlalchemy/sql/compiler.py2
2 files changed, 14 insertions, 4 deletions
diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py
index 6c98dae18..0838d810d 100644
--- a/lib/sqlalchemy/engine/result.py
+++ b/lib/sqlalchemy/engine/result.py
@@ -269,9 +269,6 @@ class ResultMetaData(object):
# high precedence keymap.
keymap.update(primary_keymap)
- if parent._echo:
- context.engine.logger.debug(
- "Col %r", tuple(x[0] for x in metadata))
@util.pending_deprecation("0.8", "sqlite dialect uses "
"_translate_colname() now")
@@ -406,7 +403,18 @@ class ResultProxy(object):
def _init_metadata(self):
metadata = self._cursor_description()
if metadata is not None:
- self._metadata = ResultMetaData(self, metadata)
+ if self.context.compiled and \
+ 'compiled_cache' in self.context.execution_options:
+ if self.context.compiled._cached_metadata:
+ self._metadata = self.context.compiled._cached_metadata
+ else:
+ self._metadata = self.context.compiled._cached_metadata = \
+ ResultMetaData(self, metadata)
+ else:
+ self._metadata = ResultMetaData(self, metadata)
+ if self._echo:
+ self.context.engine.logger.debug(
+ "Col %r", tuple(x[0] for x in metadata))
def keys(self):
"""Return the current set of string keys for rows."""
diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py
index 11608ef3b..010df5a16 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -170,6 +170,8 @@ class Compiled(object):
defaults.
"""
+ _cached_metadata = None
+
def __init__(self, dialect, statement, bind=None,
compile_kwargs=util.immutabledict()):
"""Construct a new ``Compiled`` object.