This is an automated email from the ASF dual-hosted git repository.
brondsem pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/allura.git
The following commit(s) were added to refs/heads/master by this push:
new 31a3261b3 speedup functional tests by caching jinja bytecode across
tests
31a3261b3 is described below
commit 31a3261b32eee3b95295e7d343204a3038337a7e
Author: Dave Brondsema <[email protected]>
AuthorDate: Tue Feb 4 13:16:50 2025 -0500
speedup functional tests by caching jinja bytecode across tests
---
Allura/allura/config/app_cfg.py | 21 ++++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/Allura/allura/config/app_cfg.py b/Allura/allura/config/app_cfg.py
index bf33f6ab0..d03c1a5d2 100644
--- a/Allura/allura/config/app_cfg.py
+++ b/Allura/allura/config/app_cfg.py
@@ -105,6 +105,22 @@ def on_bind(self, configurator: ForgeConfig):
self.register_engine(AlluraJinjaRenderer)
+class InMemoryBytecodeCache(jinja2.BytecodeCache):
+ def __init__(self):
+ self.cache = {}
+
+ def load_bytecode(self, bucket):
+ key = bucket.key
+ if key in self.cache:
+ bucket.code = self.cache[key]
+
+ def dump_bytecode(self, bucket):
+ key = bucket.key
+ self.cache[key] = bucket.code
+
+long_term_in_memory_bytecode_cache = InMemoryBytecodeCache()
+
+
class AlluraJinjaRenderer(JinjaRenderer):
@classmethod
@@ -112,7 +128,10 @@ def _setup_bytecode_cache(cls):
cache_type = config.get('jinja_bytecode_cache_type')
bcc = None
try:
- if cache_type == 'memcached' and config.get('memcached_host'):
+ if 'pytest' in sys.modules:
+ # speedup for tests: avoid memcache, avoid loading/dumping
bytecode to strings. Use same one for all tests
+ bcc = long_term_in_memory_bytecode_cache
+ elif cache_type == 'memcached' and config.get('memcached_host'):
import pylibmc
from jinja2 import MemcachedBytecodeCache
client = pylibmc.Client([config['memcached_host']])