Skip to content

Commit

Permalink
fix: only execute generator if value is not found in redis cache (#18472
Browse files Browse the repository at this point in the history
) (#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 fce9cce)

Co-authored-by: Daizy Modi <54097382+DaizyModi@users.noreply.github.com>
  • Loading branch information
mergify[bot] and DaizyModi committed Oct 20, 2022
1 parent 9e29a94 commit 342edb7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions frappe/model/document.py
Expand Up @@ -953,15 +953,19 @@ def run_notifications(self, method):
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
Expand Down
2 changes: 1 addition & 1 deletion frappe/utils/redis_wrapper.py
Expand Up @@ -194,7 +194,7 @@ def hget(self, name, key, generator=None, shared=False):
except redis.exceptions.ConnectionError:
pass

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

0 comments on commit 342edb7

Please sign in to comment.