Merge pull request #35420 from ankush/cache_apps
perf: Cache get_apps and internals
This commit is contained in:
commit
5e2cf89360
2 changed files with 6 additions and 2 deletions
|
|
@ -10,12 +10,14 @@ from frappe.core.doctype.installed_applications.installed_applications import (
|
|||
get_setup_wizard_completed_apps,
|
||||
get_setup_wizard_not_required_apps,
|
||||
)
|
||||
from frappe.utils.caching import request_cache
|
||||
|
||||
# check if route is /desk or /desk/* and not /app1 or /app1/*
|
||||
DESK_APP_PATTERN = re.compile(r"^/desk(/.*)?$")
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@request_cache
|
||||
def get_apps():
|
||||
apps = frappe.get_installed_apps()
|
||||
app_list = []
|
||||
|
|
|
|||
|
|
@ -1,12 +1,13 @@
|
|||
import frappe
|
||||
from frappe import _
|
||||
from frappe.utils.caching import redis_cache
|
||||
|
||||
|
||||
def get_modules_from_all_apps_for_user(user: str | None = None) -> list[dict]:
|
||||
user = user or frappe.session.user
|
||||
all_modules = get_modules_from_all_apps()
|
||||
global_blocked_modules = frappe.get_doc("User", "Administrator").get_blocked_modules()
|
||||
user_blocked_modules = frappe.get_doc("User", user).get_blocked_modules()
|
||||
global_blocked_modules = frappe.get_cached_doc("User", "Administrator").get_blocked_modules()
|
||||
user_blocked_modules = frappe.get_cached_doc("User", user).get_blocked_modules()
|
||||
blocked_modules = global_blocked_modules + user_blocked_modules
|
||||
allowed_modules_list = [m for m in all_modules if m.get("module_name") not in blocked_modules]
|
||||
|
||||
|
|
@ -29,6 +30,7 @@ def get_modules_from_all_apps():
|
|||
return modules_list
|
||||
|
||||
|
||||
@redis_cache
|
||||
def get_modules_from_app(app):
|
||||
return frappe.get_all("Module Def", filters={"app_name": app}, fields=["module_name", "app_name as app"])
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue