Merge pull request #3217 from dato/switch_edition_invalidate_active_shelves

Invalidate `active_shelf` when switching editions
This commit is contained in:
Mouse Reeve 2024-03-23 07:59:40 -07:00 committed by GitHub
commit 8bbac458a6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,6 +3,7 @@ from functools import reduce
import operator
from django.contrib.auth.decorators import login_required
from django.core.cache import cache as django_cache
from django.core.paginator import Paginator
from django.db import transaction
from django.db.models import Q
@ -104,6 +105,13 @@ def switch_edition(request):
readthrough.book = new_edition
readthrough.save()
django_cache.delete_many(
[
f"active_shelf-{request.user.id}-{book_id}"
for book_id in new_edition.parent_work.editions.values_list("id", flat=True)
]
)
reviews = models.Review.objects.filter(
book__parent_work=new_edition.parent_work, user=request.user
)