summaryrefslogtreecommitdiff
path: root/Mailman/Archiver/HyperArch.py
diff options
context:
space:
mode:
authorbwarsaw2003-05-12 15:22:12 +0000
committerbwarsaw2003-05-12 15:22:12 +0000
commit9150951f32df4a91ede39f43050ee4b7984f49d2 (patch)
tree8e7d0dfa792b805e41965cfef133116e48d07dec /Mailman/Archiver/HyperArch.py
parent8acc76ee66cc11328a582b8b55e8c7e3fb52ee4f (diff)
downloadmailman-9150951f32df4a91ede39f43050ee4b7984f49d2.tar.gz
mailman-9150951f32df4a91ede39f43050ee4b7984f49d2.tar.zst
mailman-9150951f32df4a91ede39f43050ee4b7984f49d2.zip
quick_maketext(): Richard Barrett's patch for bug #730769, with minor
stylistic modifications. This fixes caching by adding the listname to the cache key. Otherwise, lists with local overriding templates would find the wrong template. Uses the new Utils.findtext() interface.
Diffstat (limited to 'Mailman/Archiver/HyperArch.py')
-rw-r--r--Mailman/Archiver/HyperArch.py42
1 files changed, 36 insertions, 6 deletions
diff --git a/Mailman/Archiver/HyperArch.py b/Mailman/Archiver/HyperArch.py
index ea09b8778..328e0dcc6 100644
--- a/Mailman/Archiver/HyperArch.py
+++ b/Mailman/Archiver/HyperArch.py
@@ -83,6 +83,13 @@ if sys.platform == 'darwin':
resource.setrlimit(resource.RLIMIT_STACK, (newsoft, hard))
+try:
+ True, False
+except NameError:
+ True = 1
+ False = 0
+
+
def html_quote(s, lang=None):
repls = ( ('&', '&'),
@@ -159,21 +166,44 @@ quotedpat = re.compile(r'^([>|:]|>)+')
-# This doesn't need to be a weakref instance because it's just storing
-# strings. Keys are (templatefile, lang) tuples.
+# Like Utils.maketext() but with caching to improve performance.
+#
+# _templatefilepathcache is used to associate a (templatefile, lang, listname)
+# key with the file system path to a template file. This path is the one that
+# the Utils.findtext() function has computed is the one to match the values in
+# the key tuple.
+#
+# _templatecache associate a file system path as key with the text
+# returned after processing the contents of that file by Utils.findtext()
+#
+# We keep two caches to reduce the amount of template text kept in memory,
+# since the _templatefilepathcache is a many->one mapping and _templatecache
+# is a one->one mapping. Imagine 1000 lists all using the same default
+# English template.
+
+_templatefilepathcache = {}
_templatecache = {}
def quick_maketext(templatefile, dict=None, lang=None, mlist=None):
+ if mlist is None:
+ listname = ''
+ else:
+ listname = mlist._internal_name
if lang is None:
if mlist is None:
lang = mm_cfg.DEFAULT_SERVER_LANGUAGE
else:
lang = mlist.preferred_language
- template = _templatecache.get((templatefile, lang))
- if template is None:
+ cachekey = (templatefile, lang, listname)
+ filepath = _templatefilepathcache.get(cachekey)
+ if filepath:
+ template = _templatecache.get(filepath)
+ if filepath is None or template is None:
# Use the basic maketext, with defaults to get the raw template
- template = Utils.maketext(templatefile, lang=lang, raw=1)
- _templatecache[(templatefile, lang)] = template
+ template, filepath = Utils.findtext(templatefile, lang=lang,
+ raw=True, mlist=mlist)
+ _templatefilepathcache[cachekey] = filepath
+ _templatecache[filepath] = template
# Copied from Utils.maketext()
text = template
if dict is not None: