From 2b1df9aa56e5ac0eb9827f95b64a70e693ac882a Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Thu, 23 Jan 2025 12:06:36 +0530 Subject: [PATCH] perf: cache `get_events` on desk load --- frappe/desk/doctype/event/event.py | 2 ++ frappe/desk/doctype/notification_log/notification_log.py | 2 +- frappe/public/js/frappe/ui/notifications/notifications.js | 3 ++- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frappe/desk/doctype/event/event.py b/frappe/desk/doctype/event/event.py index 87ce250a0a..2f650b18fe 100644 --- a/frappe/desk/doctype/event/event.py +++ b/frappe/desk/doctype/event/event.py @@ -25,6 +25,7 @@ from frappe.utils import ( now_datetime, nowdate, ) +from frappe.utils.caching import http_cache from frappe.utils.user import get_enabled_system_users weekdays = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"] @@ -263,6 +264,7 @@ def send_event_digest(): @frappe.whitelist() +@http_cache(max_age=5 * 60, stale_while_revalidate=60 * 60) def get_events(start, end, user=None, for_reminder=False, filters=None) -> list[frappe._dict]: if not user: user = frappe.session.user diff --git a/frappe/desk/doctype/notification_log/notification_log.py b/frappe/desk/doctype/notification_log/notification_log.py index f7d2b4f21a..0812c56499 100644 --- a/frappe/desk/doctype/notification_log/notification_log.py +++ b/frappe/desk/doctype/notification_log/notification_log.py @@ -165,7 +165,7 @@ def get_email_header(doc, language: str | None = None): @frappe.whitelist() -@http_cache(max_age=60, stale_while_revalidate=5 * 60) +@http_cache(max_age=60, stale_while_revalidate=60 * 60) def get_notification_logs(limit=20): notification_logs = frappe.db.get_list( "Notification Log", fields=["*"], limit=limit, order_by="creation desc" diff --git a/frappe/public/js/frappe/ui/notifications/notifications.js b/frappe/public/js/frappe/ui/notifications/notifications.js index 8b9763057d..2cdfd5ba33 100644 --- a/frappe/public/js/frappe/ui/notifications/notifications.js +++ b/frappe/public/js/frappe/ui/notifications/notifications.js @@ -393,7 +393,8 @@ class EventsView extends BaseNotificationsView { start: today, end: today, }, - "GET" + "GET", + { cache: true } ) .then((event_list) => { this.render_events_html(event_list);