perf: ~33% faster Desk response
- hardcode `/app` resolution - use cached website settings everywhere. It was mixing cache and DB everywhere and re-quering same thing (why ?)
This commit is contained in:
parent
04aeeabb2b
commit
786df3fbeb
4 changed files with 23 additions and 12 deletions
|
|
@ -103,12 +103,12 @@ class WebsiteSettings(Document):
|
|||
def get_website_settings(context=None):
|
||||
hooks = frappe.get_hooks()
|
||||
context = frappe._dict(context or {})
|
||||
settings: "WebsiteSettings" = frappe.get_single("Website Settings")
|
||||
settings: "WebsiteSettings" = frappe.get_cached_doc("Website Settings")
|
||||
|
||||
context = context.update(
|
||||
{
|
||||
"top_bar_items": get_items("top_bar_items"),
|
||||
"footer_items": get_items("footer_items"),
|
||||
"top_bar_items": modify_header_footer_items(settings.top_bar_items),
|
||||
"footer_items": modify_header_footer_items(settings.footer_items),
|
||||
"post_login": [
|
||||
{"label": _("My Account"), "url": "/me"},
|
||||
{"label": _("Log out"), "url": "/?cmd=web_logout"},
|
||||
|
|
@ -203,22 +203,24 @@ def get_items(parentfield: str) -> list[dict]:
|
|||
order_by="idx asc",
|
||||
fields="*",
|
||||
)
|
||||
top_items = _items.copy()
|
||||
return modify_header_footer_items(_items)
|
||||
|
||||
|
||||
def modify_header_footer_items(items: list):
|
||||
top_items = items.copy()
|
||||
# attach child items to top bar
|
||||
for item in _items:
|
||||
if not item["parent_label"]:
|
||||
for item in items:
|
||||
if not item.parent_label:
|
||||
continue
|
||||
|
||||
for top_bar_item in top_items:
|
||||
if top_bar_item["label"] != item["parent_label"]:
|
||||
if top_bar_item.label != item.parent_label:
|
||||
continue
|
||||
|
||||
if "child_items" not in top_bar_item:
|
||||
if not top_bar_item.get("child_items"):
|
||||
top_bar_item["child_items"] = []
|
||||
|
||||
top_bar_item["child_items"].append(item)
|
||||
|
||||
top_bar_item.child_items.append(item)
|
||||
break
|
||||
|
||||
return top_items
|
||||
|
|
|
|||
|
|
@ -133,9 +133,9 @@ class WebsiteTheme(Document):
|
|||
|
||||
|
||||
def get_active_theme() -> Optional["WebsiteTheme"]:
|
||||
if website_theme := frappe.db.get_single_value("Website Settings", "website_theme"):
|
||||
if website_theme := frappe.get_website_settings("website_theme"):
|
||||
try:
|
||||
return frappe.get_doc("Website Theme", website_theme)
|
||||
return frappe.get_cached_doc("Website Theme", website_theme)
|
||||
except frappe.DoesNotExistError:
|
||||
pass
|
||||
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ UNSUPPORTED_STATIC_PAGE_TYPES = ("html", "md", "js", "xml", "css", "txt", "py",
|
|||
|
||||
|
||||
class StaticPage(BaseRenderer):
|
||||
__slots__ = ("path", "file_path")
|
||||
|
||||
def __init__(self, path, http_status_code=None):
|
||||
super().__init__(path=path, http_status_code=http_status_code)
|
||||
self.set_file_path()
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ from frappe.website.utils import can_cache, get_home_page
|
|||
|
||||
|
||||
class PathResolver:
|
||||
__slots__ = ("path",)
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = path.strip("/ ")
|
||||
|
||||
|
|
@ -36,6 +38,11 @@ class PathResolver:
|
|||
return frappe.flags.redirect_location, RedirectPage(self.path)
|
||||
|
||||
endpoint = resolve_path(self.path)
|
||||
|
||||
# WARN: Hardcoded for better performance
|
||||
if endpoint == "app":
|
||||
return endpoint, TemplatePage(endpoint, 200)
|
||||
|
||||
custom_renderers = self.get_custom_page_renderers()
|
||||
renderers = custom_renderers + [
|
||||
StaticPage,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue