From 521a52161fd13acac46dc17c165ebf1d42d36e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= Date: Sat, 13 Jan 2024 18:55:13 +0100 Subject: [PATCH] Invalidate `active_shelf` when switching editions Fixes: #3167. --- bookwyrm/views/books/editions.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bookwyrm/views/books/editions.py b/bookwyrm/views/books/editions.py index 54d1bd84c1..b022dbda69 100644 --- a/bookwyrm/views/books/editions.py +++ b/bookwyrm/views/books/editions.py @@ -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 @@ -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 @@ -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}")