From c8220485092f8305e9825a84c6d866361a65aa9d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 8 Jan 2022 13:04:01 -0800 Subject: [PATCH] Invalidate template cache on relationship change --- bookwyrm/models/relationship.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/bookwyrm/models/relationship.py b/bookwyrm/models/relationship.py index 03417454..2b8f240d 100644 --- a/bookwyrm/models/relationship.py +++ b/bookwyrm/models/relationship.py @@ -1,7 +1,6 @@ """ defines relationships between users """ from django.apps import apps 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.models import Q @@ -41,15 +40,10 @@ class UserRelationship(BookWyrmModel): def save(self, *args, **kwargs): """clear the template cache""" # invalidate the template cache - cache_keys = [ - make_template_fragment_key( - "follow_button", [self.user_subject.id, self.user_object.id] - ), - make_template_fragment_key( - "follow_button", [self.user_object.id, self.user_subject.id] - ), - ] - cache.delete_many(cache_keys) + cache.delete_many([ + f"relationship-{self.user_subject.id}-{self.user_object.id}", + f"relationship-{self.user_object.id}-{self.user_subject.id}", + ]) super().save(*args, **kwargs) class Meta: