mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 01:51: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:
|
if not self.user:
|
||||||
self.user = self.shelf.user
|
self.user = self.shelf.user
|
||||||
if self.id and self.user.local:
|
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)
|
super().save(*args, **kwargs)
|
||||||
|
|
||||||
def delete(self, *args, **kwargs):
|
def delete(self, *args, **kwargs):
|
||||||
if self.id and self.user.local:
|
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)
|
super().delete(*args, **kwargs)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
|
|
|
@ -17,7 +17,7 @@ def get_is_book_on_shelf(book, shelf):
|
||||||
lambda b, s: s.books.filter(id=b.id).exists(),
|
lambda b, s: s.books.filter(id=b.id).exists(),
|
||||||
book,
|
book,
|
||||||
shelf,
|
shelf,
|
||||||
timeout=15552000,
|
timeout=60 * 60, # just cache this for an hour
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ def active_shelf(context, book):
|
||||||
),
|
),
|
||||||
user,
|
user,
|
||||||
book,
|
book,
|
||||||
timeout=15552000,
|
timeout=60 * 60,
|
||||||
) or {"book": book}
|
) or {"book": book}
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,5 +85,5 @@ def latest_read_through(book, user):
|
||||||
),
|
),
|
||||||
user,
|
user,
|
||||||
book,
|
book,
|
||||||
timeout=15552000,
|
timeout=60 * 60,
|
||||||
)
|
)
|
||||||
|
|
|
@ -52,9 +52,6 @@ class ReadingStatus(View):
|
||||||
logger.exception("Invalid reading status type: %s", status)
|
logger.exception("Invalid reading status type: %s", status)
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
|
||||||
# invalidate related caches
|
|
||||||
cache.delete(f"active_shelf-{request.user.id}-{book_id}")
|
|
||||||
|
|
||||||
desired_shelf = get_object_or_404(
|
desired_shelf = get_object_or_404(
|
||||||
models.Shelf, identifier=identifier, user=request.user
|
models.Shelf, identifier=identifier, user=request.user
|
||||||
)
|
)
|
||||||
|
@ -65,6 +62,14 @@ class ReadingStatus(View):
|
||||||
.get(id=book_id)
|
.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
|
# gets the first shelf that indicates a reading status, or None
|
||||||
shelves = [
|
shelves = [
|
||||||
s
|
s
|
||||||
|
|
Loading…
Reference in a new issue