Reduces feed page queries for goals

9 fewer queries
This commit is contained in:
Mouse Reeve
2021-05-22 17:33:10 -07:00
parent 2e7d84d53c
commit 368d2cd716
3 changed files with 20 additions and 17 deletions

View File

@ -162,14 +162,15 @@ def get_suggested_books(user, max_books=5):
else max_books - book_count
)
shelf = user.shelf_set.get(identifier=preset)
shelf_books = shelf.shelfbook_set.order_by("-updated_date")[:limit]
if not shelf_books:
if not shelf.books.exists():
continue
shelf_preview = {
"name": shelf.name,
"identifier": shelf.identifier,
"books": [s.book for s in shelf_books],
"books": shelf.books.order_by("shelfbook").prefetch_related("authors")[
:limit
],
}
suggested_books.append(shelf_preview)
book_count += len(shelf_preview["books"])