aurweb/templates/partials/packages/results.html
Kevin Morris 4de18d8134
fix(FastAPI): voted/notified query efficiency
Previously, we were running a single ORM query for every single package
to check for its voted or notified states. Now, we perform a single
ORM query for each of the set of voted or notified packages in
relation with the request user.

This improves performance drastically at the expense of some
manual code additions and set-dependency; i.e. we add a bit
more complexity and roundabout way of getting our data.

Closes: https://gitlab.archlinux.org/archlinux/aurweb/-/issues/102

Signed-off-by: Kevin Morris <kevr@0cost.org>
2021-09-19 00:34:08 -07:00

57 lines
2.2 KiB
HTML

<table {% if table_id %}id="{{ table_id }}"{% endif %} class="results">
<thead>
<tr>
<th>{{ "Name" | tr }}</th>
<th>{{ "Version" | tr }}</th>
<th>{{ "Votes" | tr }}</th>
<th>{{ "Popularity" | tr }}</th>
{% if request.user.is_authenticated() %}
<th>{{ "Voted" | tr }}</th>
<th>{{ "Notify" | tr }}</th>
{% endif %}
<th>{{ "Description" | tr }}</th>
<th>{{ "Maintainer" | tr }}</th>
</tr>
</thead>
<tbody>
{% for pkg in packages %}
{% set flagged = pkg.PackageBase.OutOfDateTS %}
<tr>
<td>
<a href="/packages/{{ pkg.Name }}">
{{ pkg.Name }}
</a>
</td>
<td{% if flagged %} class="flagged"{% endif %}>{{ pkg.Version }}</td>
<td>{{ pkg.PackageBase.NumVotes }}</td>
<td>{{ pkg.PackageBase.Popularity | number_format(2) }}</td>
{% if request.user.is_authenticated() %}
<td>
{# If I voted, display "Yes". #}
{% if pkg.PackageBase.ID in votes %}
{{ "Yes" | tr }}
{% endif %}
</td>
<td>
{# If I'm being notified, display "Yes". #}
{% if pkg.PackageBase.ID in notified %}
{{ "Yes" | tr }}
{% endif %}
</td>
{% endif %}
<td class="wrap">{{ pkg.Description or '' }}</td>
<td>
{% set maintainer = pkg.PackageBase.Maintainer %}
{% if maintainer %}
<a href="/account/{{ maintainer.Username }}">
{{ maintainer.Username }}
</a>
{% else %}
<span class="error">{{ "orphan" | tr }}</span>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>