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.
This commit is contained in:
Ankush Menat 2025-01-06 13:53:06 +05:30
parent 45d414fe29
commit 29733febcb

View file

@ -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)