From 29733febcb389f178f588607e5c9e7ac33854278 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 6 Jan 2025 13:53:06 +0530 Subject: [PATCH] refactor: minor cleanup / avoid repeat calls This get+conditional set is also slightly prone to data races, but doesn't seem to be harmful as of now. Rationale: - To enable recorder one must first send a request, so this should be set long before. - While enabling we can accidentally clear cache for another worker by invalidating it, but that is kind of acceptable behaviour. We ONLY set it to False when `None` is received from Redis. Local invalidations remove it completely. --- frappe/recorder.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/frappe/recorder.py b/frappe/recorder.py index 9c6214f9bb..facdcc416d 100644 --- a/frappe/recorder.py +++ b/frappe/recorder.py @@ -175,9 +175,10 @@ def normalize_query(query: str) -> str: def record(force=False): - if frappe.client_cache.get_value(RECORDER_INTERCEPT_FLAG) or force: + flag_value = frappe.client_cache.get_value(RECORDER_INTERCEPT_FLAG) + if flag_value or force: frappe.local._recorder = Recorder(force=force) - elif frappe.client_cache.get_value(RECORDER_INTERCEPT_FLAG) is None: + elif flag_value is None: # Explicitly set it once so next requests can use client-side cache frappe.client_cache.set_value(RECORDER_INTERCEPT_FLAG, False)