diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-05 16:42:26 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-08-05 16:42:26 -0400 |
| commit | cc57ea495f6460dd56daa6de57e40047ed999369 (patch) | |
| tree | 837f5a84363c387d7f8fdeabc06928cd078028e1 /lib/sqlalchemy/engine/default.py | |
| parent | 2a946254023135eddd222974cf300ffaa5583f02 (diff) | |
| download | sqlalchemy-cc57ea495f6460dd56daa6de57e40047ed999369.tar.gz | |
Robustness for lambdas, lambda statements
in order to accommodate relationship loaders
with lambda caching, a lot more is needed. This is
a full refactor of the lambda system such that it
now has two levels of caching; the first level caches what
can be known from the __code__ element, then the next level
of caching is against the lambda itself and the contents
of __closure__. This allows for the elements inside
the lambdas, like columns and entities, to change and
then be part of the cache key. Lazy/selectinloads' use of
baked queries had to add distinct cache key elements,
which was attempted here but overall things needed to be
more robust than that.
This commit is broken out from the very long and sprawling
commit at Id6b5c03b1ce9ddb7b280f66792212a0ef0a1c541 .
Change-Id: I29a513c98917b1d503abfdd61e6b6e8800851aa8
Diffstat (limited to 'lib/sqlalchemy/engine/default.py')
| -rw-r--r-- | lib/sqlalchemy/engine/default.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/sqlalchemy/engine/default.py b/lib/sqlalchemy/engine/default.py index c431fa755..8d3c5de15 100644 --- a/lib/sqlalchemy/engine/default.py +++ b/lib/sqlalchemy/engine/default.py @@ -39,6 +39,12 @@ AUTOCOMMIT_REGEXP = re.compile( SERVER_SIDE_CURSOR_RE = re.compile(r"\s*SELECT", re.I | re.UNICODE) +CACHE_HIT = util.symbol("CACHE_HIT") +CACHE_MISS = util.symbol("CACHE_MISS") +CACHING_DISABLED = util.symbol("CACHING_DISABLED") +NO_CACHE_KEY = util.symbol("NO_CACHE_KEY") + + class DefaultDialect(interfaces.Dialect): """Default implementation of Dialect""" @@ -195,6 +201,11 @@ class DefaultDialect(interfaces.Dialect): """ + CACHE_HIT = CACHE_HIT + CACHE_MISS = CACHE_MISS + CACHING_DISABLED = CACHING_DISABLED + NO_CACHE_KEY = NO_CACHE_KEY + @util.deprecated_params( convert_unicode=( "1.3", @@ -725,6 +736,8 @@ class DefaultExecutionContext(interfaces.ExecutionContext): _expanded_parameters = util.immutabledict() + cache_hit = NO_CACHE_KEY + @classmethod def _init_ddl( cls, @@ -788,7 +801,7 @@ class DefaultExecutionContext(interfaces.ExecutionContext): parameters, invoked_statement, extracted_parameters, - cache_hit=False, + cache_hit=CACHING_DISABLED, ): """Initialize execution context for a Compiled construct.""" @@ -1026,12 +1039,19 @@ class DefaultExecutionContext(interfaces.ExecutionContext): return "raw sql" now = util.perf_counter() - if self.compiled.cache_key is None: + + ch = self.cache_hit + + if ch is NO_CACHE_KEY: return "no key %.5fs" % (now - self.compiled._gen_time,) - elif self.cache_hit: + elif ch is CACHE_HIT: return "cached since %.4gs ago" % (now - self.compiled._gen_time,) - else: + elif ch is CACHE_MISS: return "generated in %.5fs" % (now - self.compiled._gen_time,) + elif ch is CACHING_DISABLED: + return "caching disabled %.5fs" % (now - self.compiled._gen_time,) + else: + return "unknown" @util.memoized_property def engine(self): |
