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