From 5981575f0e9503d40bd35a6299bc8cc361661e35 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 4 Jan 2022 17:59:35 -0800 Subject: [PATCH] Cache template snipped for shelve buttons --- .../templates/snippets/shelve_button/shelve_button.html | 3 +++ bookwyrm/views/reading.py | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button.html b/bookwyrm/templates/snippets/shelve_button/shelve_button.html index 38f6be38c..98edac6a1 100644 --- a/bookwyrm/templates/snippets/shelve_button/shelve_button.html +++ b/bookwyrm/templates/snippets/shelve_button/shelve_button.html @@ -1,7 +1,9 @@ {% load bookwyrm_tags %} {% load utilities %} +{% load cache %} {% if request.user.is_authenticated %} +{% cache 900 shelve_button request.user.id book.id %} {% with book.id|uuid as uuid %} {% active_shelf book as active_shelf %} @@ -32,4 +34,5 @@ {% include 'snippets/reading_modals/progress_update_modal.html' with book=active_shelf.book id=modal_id readthrough=readthrough class="" %} {% endwith %} +{% endcache %} {% endif %} diff --git a/bookwyrm/views/reading.py b/bookwyrm/views/reading.py index 35847558e..6531efc23 100644 --- a/bookwyrm/views/reading.py +++ b/bookwyrm/views/reading.py @@ -1,5 +1,7 @@ """ the good stuff! the books! """ from django.contrib.auth.decorators import login_required +from django.core.cache import cache +from django.core.cache.utils import make_template_fragment_key from django.db import transaction from django.http import HttpResponse, HttpResponseBadRequest, HttpResponseNotFound from django.shortcuts import get_object_or_404, redirect @@ -44,6 +46,10 @@ class ReadingStatus(View): if not identifier: return HttpResponseBadRequest() + # invalidate the template cache + cache_key = make_template_fragment_key("shelve_button", [request.user.id, book_id]) + cache.delete(cache_key) + desired_shelf = get_object_or_404( models.Shelf, identifier=identifier, user=request.user )