perf: misc v16 fixes (#35790)

* perf: Reduce queries for setup wizard progress

These are queried on boot continuously, can just cache installed app doc.

* fix: remove stray db.commit in csrf generation
This commit is contained in:
Ankush Menat 2026-01-09 16:36:06 +05:30 committed by GitHub
parent 2a96c48637
commit 29be54a35d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 23 deletions

View file

@ -6,6 +6,7 @@ import json
import frappe import frappe
from frappe import _ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
from frappe.utils.caching import redis_cache
class InvalidAppOrder(frappe.ValidationError): class InvalidAppOrder(frappe.ValidationError):
@ -152,24 +153,16 @@ def get_installed_app_order() -> list[str]:
return frappe.get_installed_apps(_ensure_on_bench=True) return frappe.get_installed_apps(_ensure_on_bench=True)
@frappe.request_cache
def get_setup_wizard_completed_apps(): def get_setup_wizard_completed_apps():
"""Get list of apps that have completed setup wizard""" """Get list of apps that have completed setup wizard"""
return frappe.get_all( apps: InstalledApplications = frappe.client_cache.get_doc("Installed Applications")
"Installed Application", return [a.app_name for a in apps.installed_applications if a.has_setup_wizard and a.is_setup_complete]
filters={"has_setup_wizard": 1, "is_setup_complete": 1},
pluck="app_name",
)
@frappe.request_cache
def get_setup_wizard_not_required_apps(): def get_setup_wizard_not_required_apps():
"""Get list of apps that do not require setup wizard""" """Get list of apps that do not require setup wizard"""
return frappe.get_all( apps: InstalledApplications = frappe.client_cache.get_doc("Installed Applications")
"Installed Application", return [a.app_name for a in apps.installed_applications if not a.has_setup_wizard]
filters={"has_setup_wizard": 0},
pluck="app_name",
)
@frappe.request_cache @frappe.request_cache
@ -190,17 +183,14 @@ def get_apps_with_incomplete_dependencies(current_app):
return pending_apps return pending_apps
@frappe.request_cache
def get_setup_wizard_pending_apps(apps=None): def get_setup_wizard_pending_apps(apps=None):
"""Get list of apps that have completed setup wizard""" """Get list of apps that have completed setup wizard"""
filters = {"has_setup_wizard": 1, "is_setup_complete": 0} apps: InstalledApplications = frappe.client_cache.get_doc("Installed Applications")
pending_apps = [
a.app_name for a in apps.installed_applications if a.has_setup_wizard and not a.is_setup_complete
]
if apps: if apps:
filters["app_name"] = ["in", apps] pending_apps = [a for a in pending_apps if a in apps]
return frappe.get_all( return pending_apps
"Installed Application",
filters=filters,
order_by="idx",
pluck="app_name",
)

View file

@ -34,8 +34,6 @@ def get_context(context):
# this needs commit # this needs commit
csrf_token = frappe.sessions.get_csrf_token() csrf_token = frappe.sessions.get_csrf_token()
frappe.db.commit() # nosemgrep
hooks = frappe.get_hooks() hooks = frappe.get_hooks()
app_include_js = hooks.get("app_include_js", []) + frappe.conf.get("app_include_js", []) app_include_js = hooks.get("app_include_js", []) + frappe.conf.get("app_include_js", [])
app_include_css = hooks.get("app_include_css", []) + frappe.conf.get("app_include_css", []) app_include_css = hooks.get("app_include_css", []) + frappe.conf.get("app_include_css", [])