fix: massively reduce number of db queries by caching num_per_sex #27
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
2025-11-03 17:00:16 +01:00
parent e07e633651
commit 151ce0d88e

View File

@@ -1,9 +1,10 @@
{% load static %}
{% load i18n %}
<div class="grid is-col-min-2">
{% if adoption_notice.num_per_sex.F > 0 %}
{% with num_per_sex=adoption_notice.num_per_sex %}
{% if num_per_sex.F > 0 %}
<span class="cell icon-text tag is-medium">
<span class="has-text-weight-bold is-size-4">{{ adoption_notice.num_per_sex.F }} </span>
<span class="has-text-weight-bold is-size-4">{{ num_per_sex.F }}</span>
<span class="icon">
<img class="icon" src="{% static 'fellchensammlung/img/sexes/Female.png' %}"
alt="{% translate 'weibliche Tiere' %}">
@@ -11,9 +12,9 @@
</span>
{% endif %}
{% if adoption_notice.num_per_sex.I > 0 %}
{% if num_per_sex.I > 0 %}
<span class="cell icon-text tag is-medium">
<span class="has-text-weight-bold is-size-4">{{ adoption_notice.num_per_sex.I }}</span>
<span class="has-text-weight-bold is-size-4">{{ num_per_sex.I }}</span>
<span class="icon">
<img class="icon"
@@ -22,18 +23,18 @@
</span>
</span>
{% endif %}
{% if adoption_notice.num_per_sex.M > 0 %}
{% if num_per_sex.M > 0 %}
<span class="cell icon-text tag is-medium">
<span class="has-text-weight-bold is-size-4">{{ adoption_notice.num_per_sex.M }}</span>
<span class="has-text-weight-bold is-size-4">{{ num_per_sex.M }}</span>
<span class="icon">
<img class="icon" src="{% static 'fellchensammlung/img/sexes/Male.png' %}"
alt="{% translate 'männliche Tiere' %}">
</span>
</span>
{% endif %}
{% if adoption_notice.num_per_sex.M_N > 0 %}
{% if num_per_sex.M_N > 0 %}
<span class="cell icon-text tag is-medium">
<span class="has-text-weight-bold is-size-4">{{ adoption_notice.num_per_sex.M_N }}</span>
<span class="has-text-weight-bold is-size-4">{{ num_per_sex.M_N }}</span>
<span class="icon">
<img class="icon"
src="{% static 'fellchensammlung/img/sexes/Male Neutered.png' %}"
@@ -41,4 +42,5 @@
</span>
</span>
{% endif %}
{% endwith %}
</div>