Merge pull request #956 from ae-utbm/query-page-hist

Fix N+1 queries on page history
This commit is contained in:
thomas girod 2024-12-19 15:09:11 +01:00 committed by GitHub
commit 29c4a36479
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -3,17 +3,18 @@
{% macro page_history(page) %} {% macro page_history(page) %}
<p>{% trans page_name=page.name %}You're seeing the history of page "{{ page_name }}"{% endtrans %}</p> <p>{% trans page_name=page.name %}You're seeing the history of page "{{ page_name }}"{% endtrans %}</p>
<ul> <ul>
{% for r in (page.revisions.all()|sort(attribute='date', reverse=True)) %} {% set page_name = page.get_full_name() %}
{% if loop.index < 2 %} {%- for rev in page.revisions.order_by("-date").select_related("author") -%}
<li><a href="{{ url('core:page', page_name=page.get_full_name()) }}">{% trans %}last{% endtrans %}</a> - <li>
{{ user_profile_link(page.revisions.last().author) }} - {% if loop.first %}
{{ page.revisions.last().date|localtime|date(DATETIME_FORMAT) }} {{ page.revisions.last().date|localtime|time(DATETIME_FORMAT) }}</a></li> <a href="{{ url('core:page', page_name=page_name) }}">{% trans %}last{% endtrans %}</a>
{% else %} {% else %}
<li><a href="{{ url('core:page_rev', page_name=page.get_full_name(), rev=r['id']) }}">{{ r.revision }}</a> - <a href="{{ url('core:page_rev', page_name=page_name, rev=rev.id) }}">{{ rev.revision }}</a>
{{ user_profile_link(r.author) }} -
{{ r.date|localtime|date(DATETIME_FORMAT) }} {{ r.date|localtime|time(DATETIME_FORMAT) }}</a></li>
{% endif %} {% endif %}
{% endfor %} {{ user_profile_link(rev.author) }} -
{{ rev.date|localtime|date(DATETIME_FORMAT) }} {{ rev.date|localtime|time(DATETIME_FORMAT) }}
</li>
{%- endfor -%}
</ul> </ul>
{% endmacro %} {% endmacro %}