mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-12-23 08:36:32 +00:00
Use general ratings rather than privacy filtered
The original system customized how a rating is displayed to every user based on the privacy settings of the reviews and, relatedly, who the user follows. This is cool, but the query is too complicated to load in sessions, and the initial load, which isn't mitigated by caching, is too much and causes timeouts for many users. Also the cache clearing wasn't working correctly because I put in a wildcard, which does not work.
This commit is contained in:
parent
4e3c346780
commit
fc3b609ada
2 changed files with 5 additions and 5 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue