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

* fix: use of generator in

* fix: improve docstring

* fix: improve docstring

* fix: directly assign value to flags

Co-authored-by: Daizy <DaizyModi>
This commit is contained in:
Daizy Modi 2022-10-20 16:48:03 +05:30 committed by GitHub
parent 1bf384f81d
commit fce9ccedaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 6 deletions

View file

@ -950,15 +950,19 @@ class Document(BaseDocument):
from frappe.email.doctype.notification.notification import evaluate_alert
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",
fields=["name", "event", "method"],
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:
return

View file

@ -218,7 +218,7 @@ class RedisWrapper(redis.Redis):
except redis.exceptions.ConnectionError:
pass
if value:
if value is not None:
value = pickle.loads(value)
frappe.local.cache[_name][key] = value
elif generator: