From cbd75dc76612f2bc239f0ab588e5f82c8aeb2789 Mon Sep 17 00:00:00 2001 From: 0x29a Date: Fri, 27 Jan 2023 20:24:53 +0100 Subject: [PATCH 1/2] Minor performance improvements --- bookwyrm/models/annual_goal.py | 2 +- bookwyrm/models/readthrough.py | 2 +- bookwyrm/models/shelf.py | 4 ++-- bookwyrm/models/status.py | 2 +- bookwyrm/views/annual_summary.py | 6 +++--- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/bookwyrm/models/annual_goal.py b/bookwyrm/models/annual_goal.py index 53c041141..0eefacb32 100644 --- a/bookwyrm/models/annual_goal.py +++ b/bookwyrm/models/annual_goal.py @@ -52,7 +52,7 @@ class AnnualGoal(BookWyrmModel): user=self.user, book__in=book_ids, ) - return {r.book.id: r.rating for r in reviews} + return {r.book_id: r.rating for r in reviews} @property def progress(self): diff --git a/bookwyrm/models/readthrough.py b/bookwyrm/models/readthrough.py index 314b40a5c..239ec56be 100644 --- a/bookwyrm/models/readthrough.py +++ b/bookwyrm/models/readthrough.py @@ -32,7 +32,7 @@ class ReadThrough(BookWyrmModel): def save(self, *args, **kwargs): """update user active time""" - cache.delete(f"latest_read_through-{self.user.id}-{self.book.id}") + cache.delete(f"latest_read_through-{self.user_id}-{self.book_id}") self.user.update_active_date() # an active readthrough must have an unset finish date if self.finish_date or self.stopped_date: diff --git a/bookwyrm/models/shelf.py b/bookwyrm/models/shelf.py index 026571f62..8e754bc47 100644 --- a/bookwyrm/models/shelf.py +++ b/bookwyrm/models/shelf.py @@ -107,7 +107,7 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel): # remove all caches related to all editions of this book cache.delete_many( [ - f"book-on-shelf-{book.id}-{self.shelf.id}" + f"book-on-shelf-{book.id}-{self.shelf_id}" for book in self.book.parent_work.editions.all() ] ) @@ -117,7 +117,7 @@ class ShelfBook(CollectionItemMixin, BookWyrmModel): if self.id and self.user.local: cache.delete_many( [ - f"book-on-shelf-{book}-{self.shelf.id}" + f"book-on-shelf-{book}-{self.shelf_id}" for book in self.book.parent_work.editions.values_list( "id", flat=True ) diff --git a/bookwyrm/models/status.py b/bookwyrm/models/status.py index 19eab584d..bd99deee5 100644 --- a/bookwyrm/models/status.py +++ b/bookwyrm/models/status.py @@ -80,7 +80,7 @@ class Status(OrderedCollectionPageMixin, BookWyrmModel): def save(self, *args, **kwargs): """save and notify""" if self.reply_parent: - self.thread_id = self.reply_parent.thread_id or self.reply_parent.id + self.thread_id = self.reply_parent.thread_id or self.reply_parent_id super().save(*args, **kwargs) diff --git a/bookwyrm/views/annual_summary.py b/bookwyrm/views/annual_summary.py index 4f9c0a794..703a2d2ab 100644 --- a/bookwyrm/views/annual_summary.py +++ b/bookwyrm/views/annual_summary.py @@ -68,7 +68,7 @@ class AnnualSummary(View): book_list_by_pages = read_books_in_year.filter(pages__gte=0).order_by("pages") # books with no pages - no_page_list = len(read_books_in_year.filter(pages__exact=None)) + no_page_list = read_books_in_year.filter(pages__exact=None).count() # rating stats queries ratings = ( @@ -95,13 +95,13 @@ class AnnualSummary(View): "book_pages_lowest": book_list_by_pages.first(), "book_pages_highest": book_list_by_pages.last(), "no_page_number": no_page_list, - "ratings_total": len(ratings), + "ratings_total": ratings.count(), "rating_average": round( ratings_stats["rating__avg"] if ratings_stats["rating__avg"] else 0, 2 ), "book_rating_highest": ratings.order_by("-rating").first(), "best_ratings_books_ids": [ - review.book.id for review in ratings.filter(rating=5) + review.book_id for review in ratings.filter(rating=5) ], "paginated_years": paginated_years, "goal_status": goal_status, From 2605b12ed0937ad2823619f814b2144930b5a01b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 28 Jan 2023 14:18:05 +1100 Subject: [PATCH 2/2] fix sass compound selector extensions Sass changed the way compound selectors can be extended, as outlined here: https://sass-lang.com/documentation/breaking-changes/extend-compound This commit aligns the styles in shepherd.scss to the nwe compound selector extension format. --- bookwyrm/static/css/vendor/shepherd.scss | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bookwyrm/static/css/vendor/shepherd.scss b/bookwyrm/static/css/vendor/shepherd.scss index f8d39b782..5e84b2ea7 100644 --- a/bookwyrm/static/css/vendor/shepherd.scss +++ b/bookwyrm/static/css/vendor/shepherd.scss @@ -6,16 +6,16 @@ @use 'bulma/bulma.sass'; .shepherd-button { - @extend .button.mr-2; + @extend .button, .mr-2; } .shepherd-button.shepherd-button-secondary { - @extend .button.is-light; + @extend .button, .is-light; } .shepherd-footer { @extend .message-body; - @extend .is-info.is-light; + @extend .is-info, .is-light; border-color: $info-light; border-radius: 0 0 4px 4px; } @@ -29,7 +29,7 @@ .shepherd-text { @extend .message-body; - @extend .is-info.is-light; + @extend .is-info, .is-light; border-radius: 0; }