diff options
| 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 | 
| commit | 5a7d2e35af6b15e06d18b35218ff1f7fe5bf923c (patch) | |
| tree | 27555f3ca0a5794f46edcaa55fcc8f9a63cc1d42 /ishtar_common | |
| parent | 8fa45920dac4b11b82f0643839dd86c4901118e4 (diff) | |
| download | Ishtar-5a7d2e35af6b15e06d18b35218ff1f7fe5bf923c.tar.bz2 Ishtar-5a7d2e35af6b15e06d18b35218ff1f7fe5bf923c.zip | |
Fix cache menu for all users (refs #3746)
Diffstat (limited to 'ishtar_common')
| -rw-r--r-- | ishtar_common/menus.py | 37 | ||||
| -rw-r--r-- | ishtar_common/models.py | 2 | 
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) | 
