misc: cache substitution variables in substitution object (#27393)
This commit is contained in:
parent
0834c95535
commit
836da6aa97
|
@ -16,7 +16,7 @@
|
|||
|
||||
from contextlib import contextmanager
|
||||
|
||||
from quixote import get_request, get_publisher
|
||||
from quixote import get_publisher
|
||||
from quixote.html import htmltext, TemplateIO
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ def invalidate_substitution_cache(func):
|
|||
try:
|
||||
return func(*args, **kwargs)
|
||||
finally:
|
||||
Substitutions.invalidate_cache()
|
||||
get_publisher().substitutions.invalidate_cache()
|
||||
return f
|
||||
|
||||
|
||||
|
@ -81,17 +81,14 @@ class Substitutions(object):
|
|||
self.sources = orig_sources
|
||||
self.invalidate_cache()
|
||||
|
||||
@classmethod
|
||||
def invalidate_cache(cls):
|
||||
request = get_request()
|
||||
def invalidate_cache(self):
|
||||
for value in (True, False):
|
||||
if hasattr(request, '_cache_context_variables%r' % value):
|
||||
delattr(request, '_cache_context_variables%r' % value)
|
||||
if hasattr(self, '_cache_context_variables%r' % value):
|
||||
delattr(self, '_cache_context_variables%r' % value)
|
||||
|
||||
def get_context_variables(self, mode=None):
|
||||
lazy = mode in get_publisher().get_lazy_variables_modes() if mode else False
|
||||
request = get_request()
|
||||
d = getattr(request, '_cache_context_variables%r' % lazy, None)
|
||||
d = getattr(self, '_cache_context_variables%r' % lazy, None)
|
||||
if d is not None:
|
||||
return d
|
||||
d = CompatibilityNamesDict()
|
||||
|
@ -99,8 +96,7 @@ class Substitutions(object):
|
|||
d.update(source.get_substitution_variables())
|
||||
if not lazy and hasattr(source, 'get_static_substitution_variables'):
|
||||
d.update(source.get_static_substitution_variables())
|
||||
if request:
|
||||
setattr(request, '_cache_context_variables%r' % lazy, d)
|
||||
setattr(self, '_cache_context_variables%r' % lazy, d)
|
||||
return d
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in New Issue