mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-23 10:01:04 +00:00
Merge pull request #1853 from bookwyrm-social/author-page
Trying a new query to get author books
This commit is contained in:
commit
a0da5c75ff
2 changed files with 5 additions and 24 deletions
|
@ -141,12 +141,14 @@
|
||||||
<h2 class="title is-4">{% blocktrans with name=author.name %}Books by {{ name }}{% endblocktrans %}</h2>
|
<h2 class="title is-4">{% blocktrans with name=author.name %}Books by {{ name }}{% endblocktrans %}</h2>
|
||||||
<div class="columns is-multiline is-mobile">
|
<div class="columns is-multiline is-mobile">
|
||||||
{% for book in books %}
|
{% for book in books %}
|
||||||
|
{% with book=book.default_edition %}
|
||||||
<div class="column is-one-fifth-tablet is-half-mobile is-flex is-flex-direction-column">
|
<div class="column is-one-fifth-tablet is-half-mobile is-flex is-flex-direction-column">
|
||||||
<div class="is-flex-grow-1">
|
<div class="is-flex-grow-1">
|
||||||
{% include 'landing/small-book.html' with book=book %}
|
{% include 'landing/small-book.html' with book=book %}
|
||||||
</div>
|
</div>
|
||||||
{% include 'snippets/shelve_button/shelve_button.html' with book=book %}
|
{% include 'snippets/shelve_button/shelve_button.html' with book=book %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endwith %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
""" the good people stuff! the authors! """
|
""" the good people stuff! the authors! """
|
||||||
from django.contrib.auth.decorators import login_required, permission_required
|
from django.contrib.auth.decorators import login_required, permission_required
|
||||||
from django.core.paginator import Paginator
|
from django.core.paginator import Paginator
|
||||||
from django.db.models import OuterRef, Subquery, F, Q
|
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.template.response import TemplateResponse
|
from django.template.response import TemplateResponse
|
||||||
from django.utils.decorators import method_decorator
|
from django.utils.decorators import method_decorator
|
||||||
|
@ -12,7 +11,6 @@ from bookwyrm import forms, models
|
||||||
from bookwyrm.activitypub import ActivitypubResponse
|
from bookwyrm.activitypub import ActivitypubResponse
|
||||||
from bookwyrm.connectors import connector_manager
|
from bookwyrm.connectors import connector_manager
|
||||||
from bookwyrm.settings import PAGE_LENGTH
|
from bookwyrm.settings import PAGE_LENGTH
|
||||||
from bookwyrm.utils import cache
|
|
||||||
from bookwyrm.views.helpers import is_api_request
|
from bookwyrm.views.helpers import is_api_request
|
||||||
|
|
||||||
|
|
||||||
|
@ -27,28 +25,9 @@ class Author(View):
|
||||||
if is_api_request(request):
|
if is_api_request(request):
|
||||||
return ActivitypubResponse(author.to_activity())
|
return ActivitypubResponse(author.to_activity())
|
||||||
|
|
||||||
default_editions = models.Edition.objects.filter(
|
books = models.Work.objects.filter(
|
||||||
parent_work=OuterRef("parent_work")
|
authors=author, editions__authors=author
|
||||||
).order_by("-edition_rank")
|
).distinct()
|
||||||
|
|
||||||
book_ids = cache.get_or_set(
|
|
||||||
f"author-books-{author.id}",
|
|
||||||
lambda a: models.Edition.objects.filter(
|
|
||||||
Q(authors=a) | Q(parent_work__authors=a)
|
|
||||||
)
|
|
||||||
.annotate(default_id=Subquery(default_editions.values("id")[:1]))
|
|
||||||
.filter(default_id=F("id"))
|
|
||||||
.distinct()
|
|
||||||
.values_list("id", flat=True),
|
|
||||||
author,
|
|
||||||
timeout=15552000,
|
|
||||||
)
|
|
||||||
|
|
||||||
books = (
|
|
||||||
models.Edition.objects.filter(id__in=book_ids)
|
|
||||||
.order_by("-published_date", "-first_published_date", "-created_date")
|
|
||||||
.prefetch_related("authors")
|
|
||||||
)
|
|
||||||
|
|
||||||
paginated = Paginator(books, PAGE_LENGTH)
|
paginated = Paginator(books, PAGE_LENGTH)
|
||||||
page = paginated.get_page(request.GET.get("page"))
|
page = paginated.get_page(request.GET.get("page"))
|
||||||
|
|
Loading…
Reference in a new issue