mirror of
https://github.com/ae-utbm/sith.git
synced 2024-11-26 11:04:20 +00:00
Fix cache clearing
Signed-off-by: Skia <skia@libskia.so>
This commit is contained in:
parent
23293ea88e
commit
1bcde80a28
24
core/apps.py
24
core/apps.py
@ -24,34 +24,28 @@
|
|||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from django.db.models.signals import pre_save, post_save, m2m_changed
|
from django.core.signals import request_started
|
||||||
|
|
||||||
class SithConfig(AppConfig):
|
class SithConfig(AppConfig):
|
||||||
name = 'core'
|
name = 'core'
|
||||||
verbose_name = "Core app of the Sith"
|
verbose_name = "Core app of the Sith"
|
||||||
|
|
||||||
def ready(self):
|
def ready(self):
|
||||||
from core.models import User, Group
|
from core.models import User
|
||||||
from club.models import Club, Membership
|
from club.models import Club
|
||||||
from forum.models import Forum
|
from forum.models import Forum
|
||||||
|
|
||||||
def clear_cached_groups(sender, **kwargs):
|
def clear_cached_groups(**kwargs):
|
||||||
if kwargs['model'] == Group:
|
User._group_ids = {}
|
||||||
User._group_ids = {}
|
User._group_name = {}
|
||||||
User._group_name = {}
|
|
||||||
|
|
||||||
def clear_cached_memberships(sender, **kwargs):
|
def clear_cached_memberships(**kwargs):
|
||||||
User._club_memberships = {}
|
User._club_memberships = {}
|
||||||
Club._memberships = {}
|
Club._memberships = {}
|
||||||
Forum._club_memberships = {}
|
Forum._club_memberships = {}
|
||||||
|
|
||||||
print("Connecting signals!")
|
print("Connecting signals!")
|
||||||
m2m_changed.connect(clear_cached_groups, weak=False, dispatch_uid="clear_cached_groups")
|
request_started.connect(clear_cached_groups, weak=False, dispatch_uid="clear_cached_groups")
|
||||||
post_save.connect(clear_cached_memberships, weak=False, sender=Membership, # Membership is cached
|
request_started.connect(clear_cached_memberships, weak=False, dispatch_uid="clear_cached_memberships")
|
||||||
dispatch_uid="clear_cached_memberships_membership")
|
|
||||||
post_save.connect(clear_cached_memberships, weak=False, sender=Club, # Club has a cache of Membership
|
|
||||||
dispatch_uid="clear_cached_memberships_club")
|
|
||||||
post_save.connect(clear_cached_memberships, weak=False, sender=Forum, # Forum has a cache of Membership
|
|
||||||
dispatch_uid="clear_cached_memberships_forum")
|
|
||||||
# TODO: there may be a need to add more cache clearing
|
# TODO: there may be a need to add more cache clearing
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user