From 9484ea1af3141964bea7534a38b944271e082e68 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 9 Mar 2017 18:09:42 +0530 Subject: [PATCH] [fix] clear notifications for user --- frappe/desk/notifications.py | 22 ++++++++++++---------- frappe/sessions.py | 3 +++ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/frappe/desk/notifications.py b/frappe/desk/notifications.py index d01de3fdeb..dc2bdf678c 100644 --- a/frappe/desk/notifications.py +++ b/frappe/desk/notifications.py @@ -17,6 +17,7 @@ def get_notifications(): cache = frappe.cache() notification_count = {} + for name in groups: count = cache.hget("notification_count:" + name, frappe.session.user) if count is not None: @@ -108,12 +109,16 @@ def get_notifications_for_doctypes(config, notification_count): return open_count_doctype -def clear_notifications(user="*"): - if user=="*": - frappe.cache().delete_keys("notification_count:") - else: - # delete count for user - frappe.cache().hdel_keys("notification_count:", user) +def clear_notifications(user=None): + config = get_notification_config() + groups = config.get("for_doctype").keys() + config.get("for_module").keys() + cache = frappe.cache() + + for name in groups: + if user: + cache.hdel("notification_count:" + name, user) + else: + cache.delete_key("notification_count:" + name) def delete_notification_count_for(doctype): frappe.cache().delete_key("notification_count:" + doctype) @@ -126,9 +131,6 @@ def clear_doctype_notifications(doc, method=None, *args, **kwargs): delete_notification_count_for(doctype) return - if doctype in config.for_module_doctypes: - delete_notification_count_for(config.for_module_doctypes[doctype]) - def get_notification_info_for_boot(): out = get_notifications() config = get_notification_config() @@ -156,7 +158,7 @@ def get_notification_config(): config = frappe._dict() for notification_config in frappe.get_hooks().notification_config: nc = frappe.get_attr(notification_config)() - for key in ("for_doctype", "for_module", "for_module_doctypes", "for_other"): + for key in ("for_doctype", "for_module", "for_other"): config.setdefault(key, {}) config[key].update(nc.get(key, {})) return config diff --git a/frappe/sessions.py b/frappe/sessions.py index 898ced3e0c..5fa2ba27dc 100644 --- a/frappe/sessions.py +++ b/frappe/sessions.py @@ -18,6 +18,7 @@ import frappe.translate from frappe.utils.change_log import get_change_log import redis from urllib import unquote +from frappe.desk.notifications import clear_notifications @frappe.whitelist() def clear(user=None): @@ -45,6 +46,8 @@ def clear_cache(user=None): clear_global_cache() frappe.defaults.clear_cache() + clear_notifications(user) + def clear_global_cache(): frappe.model.meta.clear_cache() frappe.cache().delete_value(["app_hooks", "installed_apps",