Skip to content

Commit

Permalink
Merge pull request #355 from pratikb64/page-routing-fix-3
Browse files Browse the repository at this point in the history
fix: type annotation & add caching
  • Loading branch information
pratikb64 authored Feb 20, 2025
2 parents 145ef62 + 5e49e3a commit 8b6f925
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions wiki/wiki/doctype/wiki_page/wiki_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -638,15 +638,28 @@ def get_markdown_content(wikiPageName, wikiPagePatch):


@frappe.whitelist(allow_guest=True)
def get_page_content(wiki_page_name):
wiki_page = frappe.get_cached_doc("Wiki Page", wiki_page_name)
content = wiki_page.content
def get_page_content(wiki_page_name: str):
html_cache_key = f"wiki_page_html:{wiki_page_name}"
content = frappe.cache.hget(html_cache_key, "content")
page_title = frappe.cache.hget(html_cache_key, "page_title")
# TOC can be "None" if user has disabled it
toc_html = frappe.cache.hget(html_cache_key, "toc_html")

if not all([content, page_title]):
wiki_page = frappe.get_cached_doc("Wiki Page", wiki_page_name)
md_content = wiki_page.content

content = frappe.utils.md_to_html(md_content)
wiki_settings = frappe.get_single("Wiki Settings")
toc_html = wiki_page.calculate_toc_html(content) if wiki_settings.enable_table_of_contents else None
page_title = wiki_page.title

html = frappe.utils.md_to_html(content)
wiki_settings = frappe.get_single("Wiki Settings")
frappe.cache.hset(html_cache_key, "content", content)
frappe.cache.hset(html_cache_key, "page_title", page_title)
frappe.cache.hset(html_cache_key, "toc_html", toc_html)

return {
"title": wiki_page.title,
"content": html,
"toc_html": (wiki_page.calculate_toc_html(html) if wiki_settings.enable_table_of_contents else None),
"title": page_title,
"content": content,
"toc_html": toc_html,
}

0 comments on commit 8b6f925

Please sign in to comment.