From 435b522dbf34980c9af56b140bc5a6a76087f484 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 10 Aug 2020 11:53:39 +0530 Subject: [PATCH] fix: cache all apps in local and switch to enable/disable frappe logger --- frappe/__init__.py | 6 +++++- frappe/app.py | 19 ++++++++++--------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frappe/__init__.py b/frappe/__init__.py index c6e762919f..58207607c3 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -153,6 +153,7 @@ def init(site, sites_path=None, new_site=False): local.site = site local.sites_path = sites_path local.site_path = os.path.join(sites_path, site) + local.all_apps = None local.request_ip = None local.response = _dict({"docs":[]}) @@ -916,10 +917,13 @@ def get_installed_apps(sort=False, frappe_last=False): if not db: connect() + if not local.all_apps: + local.all_apps = get_all_apps(True) + installed = json.loads(db.get_global("installed_apps") or "[]") if sort: - installed = [app for app in get_all_apps(True) if app in installed] + installed = [app for app in local.all_apps if app in installed] if frappe_last: if 'frappe' in installed: diff --git a/frappe/app.py b/frappe/app.py index 725bec183a..39bff83122 100644 --- a/frappe/app.py +++ b/frappe/app.py @@ -99,15 +99,16 @@ def application(request): frappe.monitor.stop(response) frappe.recorder.dump() - frappe.logger("frappe.web", allow_site=frappe.local.site).info({ - "site": get_site_name(request.host), - "remote_addr": getattr(request, "remote_addr", "NOTFOUND"), - "base_url": getattr(request, "base_url", "NOTFOUND"), - "full_path": getattr(request, "full_path", "NOTFOUND"), - "method": getattr(request, "method", "NOTFOUND"), - "scheme": getattr(request, "scheme", "NOTFOUND"), - "http_status_code": getattr(response, "status_code", "NOTFOUND") - }) + if hasattr(frappe.local, 'conf') and frappe.local.conf.enable_frappe_logger: + frappe.logger("frappe.web", allow_site=frappe.local.site).info({ + "site": get_site_name(request.host), + "remote_addr": getattr(request, "remote_addr", "NOTFOUND"), + "base_url": getattr(request, "base_url", "NOTFOUND"), + "full_path": getattr(request, "full_path", "NOTFOUND"), + "method": getattr(request, "method", "NOTFOUND"), + "scheme": getattr(request, "scheme", "NOTFOUND"), + "http_status_code": getattr(response, "status_code", "NOTFOUND") + }) if response and hasattr(frappe.local, 'rate_limiter'): response.headers.extend(frappe.local.rate_limiter.headers())