Simplifies query for landing page books
This commit is contained in:
@ -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],
|
||||
}
|
||||
|
Reference in New Issue
Block a user