Skip to content

Commit

Permalink
Invalidate active_shelf when switching editions
Browse files Browse the repository at this point in the history
  • Loading branch information
dato committed Jan 13, 2024
1 parent b04ebe3 commit 0c44f97
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions bookwyrm/views/books/editions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand All @@ -14,6 +15,7 @@
from bookwyrm import forms, models
from bookwyrm.activitypub import ActivitypubResponse
from bookwyrm.settings import PAGE_LENGTH
from bookwyrm.utils import cache
from bookwyrm.views.helpers import is_api_request


Expand Down Expand Up @@ -103,4 +105,10 @@ 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)
]
)
return redirect(f"/book/{new_edition.id}")

0 comments on commit 0c44f97

Please sign in to comment.