diff --git a/src/wiki/core/markdown/__init__.py b/src/wiki/core/markdown/__init__.py index 6cc9a9fa5..58e650545 100644 --- a/src/wiki/core/markdown/__init__.py +++ b/src/wiki/core/markdown/__init__.py @@ -5,13 +5,12 @@ class ArticleMarkdown(markdown.Markdown): - def __init__(self, article, preview=False, user=None, *args, **kwargs): + def __init__(self, article, preview=False, *args, **kwargs): kwargs.update(settings.MARKDOWN_KWARGS) kwargs["extensions"] = self.get_markdown_extensions() super().__init__(*args, **kwargs) self.article = article self.preview = preview - self.user = user def core_extensions(self): """List of core extensions found in the mdx folder""" diff --git a/src/wiki/models/article.py b/src/wiki/models/article.py index 89bba2cf9..1f1e57ee6 100644 --- a/src/wiki/models/article.py +++ b/src/wiki/models/article.py @@ -207,7 +207,7 @@ class Meta: ("grant", _("Can assign permissions to other users")), ) - def render(self, preview_content=None, user=None): + def render(self, preview_content=None): if not self.current_revision: return "" if preview_content: @@ -216,7 +216,7 @@ def render(self, preview_content=None, user=None): content = self.current_revision.content return mark_safe( article_markdown( - content, self, preview=preview_content is not None, user=user + content, self, preview=preview_content is not None ) ) @@ -230,38 +230,15 @@ def get_cache_key(self): # https://github.com/django-wiki/django-wiki/issues/1065 return slugify(key_raw, allow_unicode=True) - def get_cache_content_key(self, user=None): - """Returns per-article-user cache key.""" - key_raw = "{key}:{user}".format( - key=self.get_cache_key(), user=user.get_username() if user else "" - ) - # https://github.com/django-wiki/django-wiki/issues/1065 - return slugify(key_raw, allow_unicode=True) - - def get_cached_content(self, user=None): - """Returns cached version of rendered article. - - The cache contains one "per-article" entry plus multiple - "per-article-user" entries. The per-article-user entries contain the - rendered article, the per-article entry contains list of the - per-article-user keys. The rendered article in cache (per-article-user) - is used only if the key is in the per-article entry. To delete - per-article invalidates all article cache entries.""" + def get_cached_content(self): + """Returns cached version of rendered article.""" cache_key = self.get_cache_key() - cache_content_key = self.get_cache_content_key(user) - - cached_items = cache.get(cache_key, list()) - - if cache_content_key in cached_items: - cached_content = cache.get(cache_content_key) - if cached_content is not None: - return mark_safe(cached_content) + cached_content = cache.get(cache_key) - cached_content = self.render(user=user) - cached_items.append(cache_content_key) - cache.set(cache_key, cached_items, settings.CACHE_TIMEOUT) - cache.set(cache_content_key, cached_content, settings.CACHE_TIMEOUT) + if cached_content is None: + cached_content = self.render() + cache.set(cache_key, cached_content, settings.CACHE_TIMEOUT) return mark_safe(cached_content) diff --git a/src/wiki/templatetags/wiki_tags.py b/src/wiki/templatetags/wiki_tags.py index 2d08da6f0..f3e32925e 100644 --- a/src/wiki/templatetags/wiki_tags.py +++ b/src/wiki/templatetags/wiki_tags.py @@ -50,7 +50,7 @@ def wiki_render(context, article, preview_content=None): if preview_content: content = article.render(preview_content=preview_content) elif article.current_revision: - content = article.get_cached_content(user=context.get("user")) + content = article.get_cached_content() else: content = None