This is an automated email from the ASF dual-hosted git repository.

kentontaylor 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 df2f460  When markdown conversion shouldn't be cached, check for 
existing cache first (maybe manually set in db) and also log if slow (we might 
want to improve logic here)
df2f460 is described below

commit df2f460a434e180a1279df426e68353c23c7edf8
Author: Dave Brondsema <[email protected]>
AuthorDate: Wed Feb 23 12:21:01 2022 -0500

    When markdown conversion shouldn't be cached, check for existing cache 
first (maybe manually set in db) and also log if slow (we might want to improve 
logic here)
---
 Allura/allura/lib/app_globals.py | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/Allura/allura/lib/app_globals.py b/Allura/allura/lib/app_globals.py
index 834075b..12351b8 100644
--- a/Allura/allura/lib/app_globals.py
+++ b/Allura/allura/lib/app_globals.py
@@ -100,9 +100,6 @@ class ForgeMarkdown(markdown.Markdown):
 
         """
         source_text = getattr(artifact, field_name)
-        # Check if contents macro and never cache
-        if "[[" in source_text:
-            return self.convert(source_text)
         cache_field_name = field_name + '_cache'
         cache = getattr(artifact, cache_field_name, None)
         if not cache:
@@ -132,6 +129,17 @@ class ForgeMarkdown(markdown.Markdown):
             log.warn('Skipping Markdown caching - The value for config param '
                      '"markdown_cache_threshold" must be a float.')
 
+        # Check if contains macro and never cache
+        # TODO: more precise search for [[include or [[members etc (all 
_macros). Or even track if one ran or not
+        if "[[" in source_text:
+            if render_time > 
float(config.get('markdown_cache_threshold.nocache', 0.5)):
+                try:
+                    url = artifact.url()
+                except NotImplementedError:
+                    url = ''
+                log.info(f'Not saving markdown cache since [[ means it might 
have a dynamic macro.  Took {render_time:.03}s on {artifact.index_id()} {url}')
+            return html
+
         if threshold is not None and render_time > threshold:
             # Save the cache
             if md5 is None:

Reply via email to