summaryrefslogtreecommitdiff
path: root/ishtar_common
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2018-03-01 18:29:46 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2018-03-01 18:29:46 +0100
commit586c6464996f8f9d3dfbecd365ac63acfbec6d3b (patch)
tree27555f3ca0a5794f46edcaa55fcc8f9a63cc1d42 /ishtar_common
parentb6c60e6e5e5709a18f3fc89cee8baca7e08a7fc3 (diff)
downloadIshtar-586c6464996f8f9d3dfbecd365ac63acfbec6d3b.tar.bz2
Ishtar-586c6464996f8f9d3dfbecd365ac63acfbec6d3b.zip
Fix cache menu for all users (refs #3746)
Diffstat (limited to 'ishtar_common')
-rw-r--r--ishtar_common/menus.py37
-rw-r--r--ishtar_common/models.py2
2 files changed, 30 insertions, 9 deletions
diff --git a/ishtar_common/menus.py b/ishtar_common/menus.py
index e00c6fbef..7cc7b751e 100644
--- a/ishtar_common/menus.py
+++ b/ishtar_common/menus.py
@@ -72,22 +72,43 @@ class Menu:
self.session = session
self.items_by_idx = {}
- def set_menu_updated_key(self):
- cache_key = u"{}-{}".format(
- settings.PROJECT_SLUG, 'menu_updated')
+ def reinit_menu_for_all_user(self):
+ lst_cache_key = u"{}-{}".format(
+ settings.PROJECT_SLUG, 'menu_updated_list',
+ )
+ lst_ids = cache.get(lst_cache_key)
+ if not lst_ids:
+ return
+ for idx in lst_ids:
+ self.init(idx, force=True)
+
+ def set_menu_updated_key(self, cache_key, user_id):
+ lst_cache_key = u"{}-{}".format(
+ settings.PROJECT_SLUG, 'menu_updated_list',
+ )
+ lst_ids = cache.get(lst_cache_key)
+ if not lst_ids:
+ lst_ids = []
+ if not lst_ids or user_id not in lst_ids:
+ lst_ids.append(user_id)
+ cache.set(lst_cache_key, lst_ids, settings.CACHE_TIMEOUT)
+
time = unicode(datetime.datetime.now().isoformat())
cache.set(cache_key, time, settings.CACHE_TIMEOUT)
self.initialized = time
- def init(self, force=False):
- cache_key = u"{}-{}".format(
- settings.PROJECT_SLUG, 'menu_updated')
+ def init(self, user_id=0, force=False):
+ if not user_id and self.user:
+ user_id = self.user.pk
+ cache_key = u"{}-{}-{}".format(
+ settings.PROJECT_SLUG, 'menu_updated',
+ user_id
+ )
menu_updated = cache.get(cache_key)
if not force and menu_updated and self.initialized \
and self.initialized == menu_updated:
return
- menu_updated = cache.get(cache_key)
- self.set_menu_updated_key()
+ self.set_menu_updated_key(cache_key, user_id)
self.items = {}
self.items_by_idx = {}
for idx, main_menu in enumerate(self.childs):
diff --git a/ishtar_common/models.py b/ishtar_common/models.py
index b20392656..839a71d39 100644
--- a/ishtar_common/models.py
+++ b/ishtar_common/models.py
@@ -1687,7 +1687,7 @@ def get_current_profile(force=False):
def cached_site_changed(sender, **kwargs):
get_current_profile(force=True)
from ishtar_common.menus import menu
- menu.init(force=True)
+ menu.reinit_menu_for_all_user()
post_save.connect(cached_site_changed, sender=IshtarSiteProfile)