Browse Source

[fix] clear notifications for user

version-14
Rushabh Mehta 8 years ago
parent
commit
9484ea1af3
2 changed files with 15 additions and 10 deletions
  1. +12
    -10
      frappe/desk/notifications.py
  2. +3
    -0
      frappe/sessions.py

+ 12
- 10
frappe/desk/notifications.py View File

@@ -17,6 +17,7 @@ def get_notifications():
cache = frappe.cache() cache = frappe.cache()


notification_count = {} notification_count = {}

for name in groups: for name in groups:
count = cache.hget("notification_count:" + name, frappe.session.user) count = cache.hget("notification_count:" + name, frappe.session.user)
if count is not None: if count is not None:
@@ -108,12 +109,16 @@ def get_notifications_for_doctypes(config, notification_count):


return open_count_doctype 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): def delete_notification_count_for(doctype):
frappe.cache().delete_key("notification_count:" + 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) delete_notification_count_for(doctype)
return return


if doctype in config.for_module_doctypes:
delete_notification_count_for(config.for_module_doctypes[doctype])

def get_notification_info_for_boot(): def get_notification_info_for_boot():
out = get_notifications() out = get_notifications()
config = get_notification_config() config = get_notification_config()
@@ -156,7 +158,7 @@ def get_notification_config():
config = frappe._dict() config = frappe._dict()
for notification_config in frappe.get_hooks().notification_config: for notification_config in frappe.get_hooks().notification_config:
nc = frappe.get_attr(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.setdefault(key, {})
config[key].update(nc.get(key, {})) config[key].update(nc.get(key, {}))
return config return config


+ 3
- 0
frappe/sessions.py View File

@@ -18,6 +18,7 @@ import frappe.translate
from frappe.utils.change_log import get_change_log from frappe.utils.change_log import get_change_log
import redis import redis
from urllib import unquote from urllib import unquote
from frappe.desk.notifications import clear_notifications


@frappe.whitelist() @frappe.whitelist()
def clear(user=None): def clear(user=None):
@@ -45,6 +46,8 @@ def clear_cache(user=None):
clear_global_cache() clear_global_cache()
frappe.defaults.clear_cache() frappe.defaults.clear_cache()


clear_notifications(user)

def clear_global_cache(): def clear_global_cache():
frappe.model.meta.clear_cache() frappe.model.meta.clear_cache()
frappe.cache().delete_value(["app_hooks", "installed_apps", frappe.cache().delete_value(["app_hooks", "installed_apps",


Loading…
Cancel
Save