Commit 6a08e141 authored by Maël Kervella's avatar Maël Kervella

Otimize DB request for the right page

Reimplement end_adhesion and is_adherent methods in the
query itself so it can be done in a single query and not
done for each user individually.
parent 324b48d3
......@@ -70,7 +70,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for user in superusers %}
<tr>
<td>{{ user.pseudo }}</td>
{% if user.is_adherent %}
{% if user.end_adhesion is not None and user.end_adhesion >= now %}
<td class="text-success">{% trans "Member" %}</td>
{% elif not user.end_adhesion %}
<td class="text-warning">{% trans "No membership records" %}</td>
......@@ -175,7 +175,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
{% for user in users %}
<tr>
<td>{{ user.pseudo }}</td>
{% if user.is_adherent %}
{% if user.end_adhesion is not None and user.end_adhesion >= now %}
<td class="text-success">{% trans "Member" %}</td>
{% elif not user.end_adhesion %}
<td class="text-warning">{% trans "No membership records" %}</td>
......
......@@ -811,15 +811,18 @@ def index_listright(request):
.order_by('name')
.prefetch_related('permissions')
.prefetch_related('user_set')
.prefetch_related('user_set__facture_set__vente_set__cotisation')
):
rights[right] = (right.user_set
.annotate(action_number=Count('revision'),
last_seen=Max('revision__date_created'))
last_seen=Max('revision__date_created'),
end_adhesion=Max('facture__vente__cotisation__date_end'))
)
superusers = (User.objects
.filter(is_superuser=True)
.annotate(action_number=Count('revision'),
last_seen=Max('revision__date_created'))
last_seen=Max('revision__date_created'),
end_adhesion=Max('facture__vente__cotisation__date_end'))
)
return render(
request,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment