forked from mirrors/bookwyrm
Invalidate template cache on relationship change
This commit is contained in:
parent
f2f40cf3b9
commit
c822048509
1 changed files with 4 additions and 10 deletions
|
@ -1,7 +1,6 @@
|
||||||
""" defines relationships between users """
|
""" defines relationships between users """
|
||||||
from django.apps import apps
|
from django.apps import apps
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.core.cache.utils import make_template_fragment_key
|
|
||||||
from django.db import models, transaction, IntegrityError
|
from django.db import models, transaction, IntegrityError
|
||||||
from django.db.models import Q
|
from django.db.models import Q
|
||||||
|
|
||||||
|
@ -41,15 +40,10 @@ class UserRelationship(BookWyrmModel):
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
"""clear the template cache"""
|
"""clear the template cache"""
|
||||||
# invalidate the template cache
|
# invalidate the template cache
|
||||||
cache_keys = [
|
cache.delete_many([
|
||||||
make_template_fragment_key(
|
f"relationship-{self.user_subject.id}-{self.user_object.id}",
|
||||||
"follow_button", [self.user_subject.id, self.user_object.id]
|
f"relationship-{self.user_object.id}-{self.user_subject.id}",
|
||||||
),
|
])
|
||||||
make_template_fragment_key(
|
|
||||||
"follow_button", [self.user_object.id, self.user_subject.id]
|
|
||||||
),
|
|
||||||
]
|
|
||||||
cache.delete_many(cache_keys)
|
|
||||||
super().save(*args, **kwargs)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
Loading…
Reference in a new issue