From c28d077cb4b5d62b6abd8d50d0304e9ae5fc953d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 7 Aug 2021 17:12:09 -0700 Subject: [PATCH] Simplifies query for landing page books --- bookwyrm/templates/landing/landing.html | 12 +++++------ bookwyrm/views/helpers.py | 28 +++++++++++-------------- 2 files changed, 18 insertions(+), 22 deletions(-) diff --git a/bookwyrm/templates/landing/landing.html b/bookwyrm/templates/landing/landing.html index 3879e987..7a30f161 100644 --- a/bookwyrm/templates/landing/landing.html +++ b/bookwyrm/templates/landing/landing.html @@ -10,18 +10,18 @@
- {% include 'landing/large-book.html' with book=books.has_description.0 %} + {% include 'landing/large-book.html' with book=books.0 %}
- {% include 'landing/small-book.html' with book=books.no_description.0 %} + {% include 'landing/small-book.html' with book=books.1 %}
- {% include 'landing/small-book.html' with book=books.no_description.1 %} + {% include 'landing/small-book.html' with book=books.2 %}
@@ -30,18 +30,18 @@
- {% include 'landing/small-book.html' with book=books.no_description.2 %} + {% include 'landing/small-book.html' with book=books.3 %}
- {% include 'landing/small-book.html' with book=books.no_description.3 %} + {% include 'landing/small-book.html' with book=books.4 %}
- {% include 'landing/large-book.html' with book=books.has_description.1 %} + {% include 'landing/large-book.html' with book=books.5 %}
diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index 0add1469..b1e5f68c 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -2,7 +2,7 @@ import re from requests import HTTPError from django.core.exceptions import FieldError -from django.db.models import Max, Q +from django.db.models import Q from django.http import Http404 from bookwyrm import activitypub, models @@ -165,20 +165,16 @@ def is_blocked(viewer, user): def get_landing_books(): """list of books for the landing page""" - options = ( - models.Edition.objects.filter( - review__published_date__isnull=False, - review__deleted=False, - review__user__local=True, - review__privacy__in=["public", "unlisted"], + return list( + set( + models.Edition.objects.filter( + review__published_date__isnull=False, + review__deleted=False, + review__user__local=True, + review__privacy__in=["public", "unlisted"], + ) + .exclude(cover__exact="") + .distinct() + .order_by("-review__published_date")[:6] ) - .exclude(cover__exact="") - .annotate(Max("review__published_date")) - .order_by("-review__published_date__max") ) - - has_description = options.exclude(description=None).exclude(description="") - return { - "has_description": has_description[:2], - "no_description": options.exclude(id__in=has_description)[:4], - }