mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
fd9b07c429
commit
4de18d8134
5 changed files with 126 additions and 11 deletions
|
@ -5,7 +5,11 @@
|
|||
{% if not flagged_packages %}
|
||||
<p>{{ "No packages matched your search criteria." | tr }}</p>
|
||||
{% else %}
|
||||
{% with table_id = "flagged-packages", packages = flagged_packages %}
|
||||
{% with table_id = "flagged-packages",
|
||||
packages = flagged_packages,
|
||||
votes = flagged_packages_voted,
|
||||
notified = flagged_packages_notified
|
||||
%}
|
||||
{% include 'partials/packages/results.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
@ -30,7 +34,10 @@
|
|||
{% if not packages %}
|
||||
<p>{{ "No packages matched your search criteria." | tr }}</p>
|
||||
{% else %}
|
||||
{% with table_id = "my-packages" %}
|
||||
{% with table_id = "my-packages",
|
||||
votes = packages_voted,
|
||||
notified = packages_notified
|
||||
%}
|
||||
{% include 'partials/packages/results.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
@ -46,7 +53,11 @@
|
|||
{% if not comaintained %}
|
||||
<p>{{ "No packages matched your search criteria." | tr }}</p>
|
||||
{% else %}
|
||||
{% with table_id = "comaintained-packages", packages = comaintained %}
|
||||
{% with table_id = "comaintained-packages",
|
||||
packages = comaintained,
|
||||
votes = comaintained_voted,
|
||||
notified = comaintained_notified
|
||||
%}
|
||||
{% include 'partials/packages/results.html' %}
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
|
|
@ -28,14 +28,14 @@
|
|||
<td>{{ pkg.PackageBase.Popularity | number_format(2) }}</td>
|
||||
{% if request.user.is_authenticated() %}
|
||||
<td>
|
||||
<!-- If I voted, display "Yes". -->
|
||||
{% if request.user.voted_for(pkg) %}
|
||||
{# If I voted, display "Yes". #}
|
||||
{% if pkg.PackageBase.ID in votes %}
|
||||
{{ "Yes" | tr }}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
<!-- If I'm being notified, display "Yes". -->
|
||||
{% if request.user.notified(pkg) %}
|
||||
{# If I'm being notified, display "Yes". #}
|
||||
{% if pkg.PackageBase.ID in notified %}
|
||||
{{ "Yes" | tr }}
|
||||
{% endif %}
|
||||
</td>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue