Merge pull request #1811 from bookwyrm-social/cache-fix

Fixes active readthrough cache bug
This commit is contained in:
Mouse Reeve 2022-01-11 13:11:02 -08:00 committed by GitHub
commit e378e74901
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -132,18 +132,20 @@ def related_status(notification):
def active_shelf(context, book): def active_shelf(context, book):
"""check what shelf a user has a book on, if any""" """check what shelf a user has a book on, if any"""
user = context["request"].user user = context["request"].user
return cache.get_or_set( return (
f"active_shelf-{user.id}-{book.id}", cache.get_or_set(
lambda u, b: ( f"active_shelf-{user.id}-{book.id}",
models.ShelfBook.objects.filter( lambda u, b: (
shelf__user=u, models.ShelfBook.objects.filter(
book__parent_work__editions=b, shelf__user=u,
).first() book__parent_work__editions=b,
).first()
),
user,
book,
timeout=15552000,
) )
or {"book": book}, or {"book": book}
user,
book,
timeout=15552000,
) )