forked from mirrors/bookwyrm
Improves query efficiency for shelve buttons
About 50 fewer queries (yikes)
This commit is contained in:
parent
368d2cd716
commit
3d3ab6433e
6 changed files with 9 additions and 8 deletions
|
@ -5,7 +5,7 @@
|
|||
<div class="select is-small mt-1 mb-3">
|
||||
<select name="{{ book.id }}" aria-label="{% blocktrans with book_title=book.title %}Have you read {{ book_title }}?{% endblocktrans %}">
|
||||
<option disabled selected value>Add to your books</option>
|
||||
{% for shelf in request.user.shelf_set.all %}
|
||||
{% for shelf in user_shelves %}
|
||||
<option value="{{ shelf.id }}">{{ shelf.name }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
|
|
|
@ -193,8 +193,11 @@
|
|||
|
||||
<div class="section is-flex-grow-1">
|
||||
<div class="container">
|
||||
{# almost every view needs to know the user shelves #}
|
||||
{% with request.user.shelf_set.all as user_shelves %}
|
||||
{% block content %}
|
||||
{% endblock %}
|
||||
{% endwith %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block dropdown-list %}
|
||||
{% for shelf in request.user.shelf_set.all %}
|
||||
{% for shelf in user_shelves %}
|
||||
<li role="menuitem" class="dropdown-item p-0">
|
||||
<form name="shelve" action="/shelve/" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
</div>
|
||||
{% else %}
|
||||
<div class="control">
|
||||
{% include 'snippets/shelve_button/shelve_button_options.html' with class="shelf-option is-small" shelves=request.user.shelf_set.all active_shelf=active_shelf button_uuid=uuid %}
|
||||
{% include 'snippets/shelve_button/shelve_button_options.html' with class="shelf-option is-small" shelves=user_shelves active_shelf=active_shelf button_uuid=uuid %}
|
||||
</div>
|
||||
{% include 'snippets/shelve_button/shelve_button_dropdown.html' with class="is-small" button_uuid=uuid%}
|
||||
{% endif %}
|
||||
|
@ -25,7 +25,7 @@
|
|||
|
||||
{% include 'snippets/shelve_button/finish_reading_modal.html' with book=active_shelf.book controls_text="finish-reading" controls_uid=uuid readthrough=readthrough %}
|
||||
|
||||
{% include 'snippets/shelve_button/progress_update_modal.html' with book=shelf_book.book controls_text="progress-update" controls_uid=uuid readthrough=readthrough %}
|
||||
{% include 'snippets/shelve_button/progress_update_modal.html' with book=active_shelf_book.book controls_text="progress-update" controls_uid=uuid readthrough=readthrough %}
|
||||
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
|
|
@ -7,5 +7,5 @@
|
|||
{% endblock %}
|
||||
|
||||
{% block dropdown-list %}
|
||||
{% include 'snippets/shelve_button/shelve_button_options.html' with active_shelf=active_shelf shelves=request.user.shelf_set.all dropdown=True class="shelf-option is-fullwidth is-small is-radiusless is-white" %}
|
||||
{% include 'snippets/shelve_button/shelve_button_options.html' with active_shelf=active_shelf shelves=user_shelves dropdown=True class="shelf-option is-fullwidth is-small is-radiusless is-white" %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -3,8 +3,6 @@ from django import template
|
|||
from django.db.models import Avg
|
||||
|
||||
from bookwyrm import models, views
|
||||
from bookwyrm.views.status import to_markdown
|
||||
from bookwyrm.templatetags.utilities import get_user_identifier
|
||||
|
||||
|
||||
register = template.Library()
|
||||
|
@ -73,7 +71,7 @@ def active_shelf(context, book):
|
|||
"""check what shelf a user has a book on, if any"""
|
||||
shelf = models.ShelfBook.objects.filter(
|
||||
shelf__user=context["request"].user, book__in=book.parent_work.editions.all()
|
||||
).first()
|
||||
).select_related("book", "shelf").first()
|
||||
return shelf if shelf else {"book": book}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue