1
0
Fork 0

Cache book_titleby only for 10 seconds

This should be enough caching when renderering pages like the feed, but
not so much that editing a book or author will not show the updated data.
At least without having to do some clever cache busting.
This commit is contained in:
Christof Dorner 2022-12-20 21:48:14 +01:00
parent 5ea922a551
commit 3e25b04e4a
3 changed files with 2 additions and 18 deletions

View file

@ -1,8 +1,6 @@
""" database schema for info about authors """
import re
from django.contrib.postgres.indexes import GinIndex
from django.core.cache import cache
from django.core.cache.utils import make_template_fragment_key
from django.db import models
from bookwyrm import activitypub
@ -37,16 +35,7 @@ class Author(BookDataModel):
bio = fields.HtmlField(null=True, blank=True)
def save(self, *args, **kwargs):
"""clear related template caches"""
# clear template caches
if self.id:
cache_keys = [
make_template_fragment_key("titleby", [book])
for book in self.book_set.values_list("id", flat=True)
]
cache.delete_many(cache_keys)
# normalize isni format
"""normalize isni format"""
if self.isni:
self.isni = re.sub(r"\s", "", self.isni)