diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 1e31de774..f37076b5c 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -374,7 +374,7 @@ class Review(BookStatus): def save(self, *args, **kwargs): """clear rating caches""" if self.book.parent_work: - cache.delete(f"book-rating-{self.book.parent_work.id}-*") + cache.delete(f"book-rating-{self.book.parent_work.id}") super().save(*args, **kwargs) diff --git a/bookwyrm/templatetags/rating_tags.py b/bookwyrm/templatetags/rating_tags.py index 670599e25..cc23d3308 100644 --- a/bookwyrm/templatetags/rating_tags.py +++ b/bookwyrm/templatetags/rating_tags.py @@ -13,10 +13,10 @@ register = template.Library() def get_rating(book, user): """get the overall rating of a book""" return cache.get_or_set( - f"book-rating-{book.parent_work.id}-{user.id}", - lambda u, b: models.Review.privacy_filter(u) - .filter(book__parent_work__editions=b, rating__gt=0) - .aggregate(Avg("rating"))["rating__avg"] + f"book-rating-{book.parent_work.id}", + lambda u, b: models.Review.objects.filter( + book__parent_work__editions=b, rating__gt=0 + ).aggregate(Avg("rating"))["rating__avg"] or 0, user, book,