mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-26 11:31:08 +00:00
Merge pull request #2195 from bookwyrm-social/a-farcical-parade-of-errors-when-reading-multiple-editions
A farcical parade of errors when reading multiple editions
This commit is contained in:
commit
2eaffc7249
3 changed files with 26 additions and 8 deletions
|
@ -103,12 +103,25 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel):
|
|||
if not self.user:
|
||||
self.user = self.shelf.user
|
||||
if self.id and self.user.local:
|
||||
cache.delete(f"book-on-shelf-{self.book.id}-{self.shelf.id}")
|
||||
# remove all caches related to all editions of this book
|
||||
cache.delete_many(
|
||||
[
|
||||
f"book-on-shelf-{book.id}-{self.shelf.id}"
|
||||
for book in self.book.parent_work.editions.all()
|
||||
]
|
||||
)
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def delete(self, *args, **kwargs):
|
||||
if self.id and self.user.local:
|
||||
cache.delete(f"book-on-shelf-{self.book.id}-{self.shelf.id}")
|
||||
cache.delete_many(
|
||||
[
|
||||
f"book-on-shelf-{book}-{self.shelf.id}"
|
||||
for book in self.book.parent_work.editions.values_list(
|
||||
"id", flat=True
|
||||
)
|
||||
]
|
||||
)
|
||||
super().delete(*args, **kwargs)
|
||||
|
||||
class Meta:
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -52,9 +52,6 @@ class ReadingStatus(View):
|
|||
logger.exception("Invalid reading status type: %s", status)
|
||||
return HttpResponseBadRequest()
|
||||
|
||||
# invalidate related caches
|
||||
cache.delete(f"active_shelf-{request.user.id}-{book_id}")
|
||||
|
||||
desired_shelf = get_object_or_404(
|
||||
models.Shelf, identifier=identifier, user=request.user
|
||||
)
|
||||
|
@ -65,6 +62,14 @@ class ReadingStatus(View):
|
|||
.get(id=book_id)
|
||||
)
|
||||
|
||||
# invalidate related caches
|
||||
cache.delete_many(
|
||||
[
|
||||
f"active_shelf-{request.user.id}-{ed}"
|
||||
for ed in book.parent_work.editions.values_list("id", flat=True)
|
||||
]
|
||||
)
|
||||
|
||||
# gets the first shelf that indicates a reading status, or None
|
||||
shelves = [
|
||||
s
|
||||
|
|
Loading…
Reference in a new issue