diff options
| author | Federico Caselli <cfederico87@gmail.com> | 2022-06-18 21:08:27 +0000 |
|---|---|---|
| committer | Gerrit Code Review <gerrit@ci3.zzzcomputing.com> | 2022-06-18 21:08:27 +0000 |
| commit | be576e7d88b6038781e52f7ef79799dbad09cd54 (patch) | |
| tree | 772c368e107d13537ad8fb030b2b02fb1638169b /lib/sqlalchemy/sql/cache_key.py | |
| parent | f7daad21ef66c29aecfbdb2b967641d0adad8779 (diff) | |
| parent | db08a699489c9b0259579d7ff7fd6bf3496ca3a2 (diff) | |
| download | sqlalchemy-be576e7d88b6038781e52f7ef79799dbad09cd54.tar.gz | |
Merge "rearchitect reflection for batched performance" into main
Diffstat (limited to 'lib/sqlalchemy/sql/cache_key.py')
| -rw-r--r-- | lib/sqlalchemy/sql/cache_key.py | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/sqlalchemy/sql/cache_key.py b/lib/sqlalchemy/sql/cache_key.py index c16fbdae1..5922c2db0 100644 --- a/lib/sqlalchemy/sql/cache_key.py +++ b/lib/sqlalchemy/sql/cache_key.py @@ -12,6 +12,7 @@ from itertools import zip_longest import typing from typing import Any from typing import Dict +from typing import Iterable from typing import Iterator from typing import List from typing import MutableMapping @@ -546,6 +547,43 @@ class CacheKey(NamedTuple): return target_element.params(translate) +def _ad_hoc_cache_key_from_args( + tokens: Tuple[Any, ...], + traverse_args: Iterable[Tuple[str, InternalTraversal]], + args: Iterable[Any], +) -> Tuple[Any, ...]: + """a quick cache key generator used by reflection.flexi_cache.""" + bindparams: List[BindParameter[Any]] = [] + + _anon_map = anon_map() + + tup = tokens + + for (attrname, sym), arg in zip(traverse_args, args): + key = sym.name + visit_key = key.replace("dp_", "visit_") + + if arg is None: + tup += (attrname, None) + continue + + meth = getattr(_cache_key_traversal_visitor, visit_key) + if meth is CACHE_IN_PLACE: + tup += (attrname, arg) + elif meth in ( + CALL_GEN_CACHE_KEY, + STATIC_CACHE_KEY, + ANON_NAME, + PROPAGATE_ATTRS, + ): + raise NotImplementedError( + f"Haven't implemented symbol {meth} for ad-hoc key from args" + ) + else: + tup += meth(attrname, arg, None, _anon_map, bindparams) + return tup + + class _CacheKeyTraversal(HasTraversalDispatch): # very common elements are inlined into the main _get_cache_key() method # to produce a dramatic savings in Python function call overhead |
