Dramatically reduce cache duration for reading statuses

I originally set this for a very long timeout because this value should
be invalidated when it needs to be by the models, and if that worked
perfectly, this would reduce queries dramatically for books that show up
in ones feed frequently, but don't change status (for example, a book
you read and your friend is currently posting about). In practice, of
course, there are errors in invalidating this cache which leave this
value appearing extremely broken and it's next to impossible to fix.

This change makes each of the timeouts related to reading an hour, which
will still give performance benefit when browsing the site (especially
for loading the same book multiple times on a page), but resolve
naturally if the cache gets into a bad state.
This commit is contained in:
Mouse Reeve 2022-07-07 12:06:06 -07:00
parent 8e18c21460
commit 076ba6f0ae

View file

@ -17,7 +17,7 @@ def get_is_book_on_shelf(book, shelf):
lambda b, s: s.books.filter(id=b.id).exists(),
book,
shelf,
timeout=15552000,
timeout=60*60, # just cache this for an hour
)
@ -68,7 +68,7 @@ def active_shelf(context, book):
),
user,
book,
timeout=15552000,
timeout=60*60,
) or {"book": book}
@ -85,5 +85,5 @@ def latest_read_through(book, user):
),
user,
book,
timeout=15552000,
timeout=60*60,
)