Procházet zdrojové kódy

fix: only execute generator if value is not found in redis cache (#18472) (#18479)

* fix: use of generator in

* fix: improve docstring

* fix: improve docstring

* fix: directly assign value to flags

Co-authored-by: Daizy <DaizyModi>
(cherry picked from commit fce9ccedaa)

Co-authored-by: Daizy Modi <54097382+DaizyModi@users.noreply.github.com>
version-14
mergify[bot] před 2 roky
committed by GitHub
rodič
revize
342edb76bf
V databázi nebyl nalezen žádný známý klíč pro tento podpis ID GPG klíče: 4AEE18F83AFDEB23
2 změnil soubory, kde provedl 10 přidání a 6 odebrání
  1. +9
    -5
      frappe/model/document.py
  2. +1
    -1
      frappe/utils/redis_wrapper.py

+ 9
- 5
frappe/model/document.py Zobrazit soubor

@@ -953,15 +953,19 @@ class Document(BaseDocument):
from frappe.email.doctype.notification.notification import evaluate_alert from frappe.email.doctype.notification.notification import evaluate_alert


if self.flags.notifications is None: if self.flags.notifications is None:
alerts = frappe.cache().hget("notifications", self.doctype)
if alerts is None:
alerts = frappe.get_all(

def _get_notifications():
"""returns enabled notifications for the current doctype"""

return frappe.get_all(
"Notification", "Notification",
fields=["name", "event", "method"], fields=["name", "event", "method"],
filters={"enabled": 1, "document_type": self.doctype}, filters={"enabled": 1, "document_type": self.doctype},
) )
frappe.cache().hset("notifications", self.doctype, alerts)
self.flags.notifications = alerts

self.flags.notifications = frappe.cache().hget(
"notifications", self.doctype, _get_notifications
)


if not self.flags.notifications: if not self.flags.notifications:
return return


+ 1
- 1
frappe/utils/redis_wrapper.py Zobrazit soubor

@@ -194,7 +194,7 @@ class RedisWrapper(redis.Redis):
except redis.exceptions.ConnectionError: except redis.exceptions.ConnectionError:
pass pass


if value:
if value is not None:
value = pickle.loads(value) value = pickle.loads(value)
frappe.local.cache[_name][key] = value frappe.local.cache[_name][key] = value
elif generator: elif generator:


Načítá se…
Zrušit
Uložit