fix(packages.search): fix default ordering & improve performance

- Use queries more closely aligned to PHP's implementation; removes
  the need for separate vote/notification queries.
- Default sort by popularity

Closes #214

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-12-23 19:20:10 -08:00
parent e75aa386ea
commit 56bd60559c
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
7 changed files with 161 additions and 90 deletions

View file

@ -45,7 +45,7 @@
{# /packages does things a bit roundabout-wise:
If SeB is not given, "nd" is the default.
If SB is not given, "n" is the default.
If SB is not given, "p" is the default.
If SO is not given, "d" is the default.
However, we depend on flipping SO for column sorting.
@ -56,7 +56,7 @@
{% set SeB = "nd" %}
{% endif %}
{% if not SB %}
{% set SB = "n" %}
{% set SB = "p" %}
{% endif %}
{% if not SO %}
{% set SO = "d" %}

View file

@ -64,7 +64,7 @@
</thead>
<tbody>
{% for pkg in packages %}
{% set flagged = pkg.PackageBase.OutOfDateTS %}
{% set flagged = pkg.OutOfDateTS %}
<tr>
{% if request.user.is_authenticated() %}
<td>
@ -81,28 +81,27 @@
{% else %}
<td>{{ pkg.Version }}</td>
{% endif %}
<td>{{ pkg.PackageBase.NumVotes }}</td>
<td>{{ pkg.NumVotes }}</td>
<td>
{{ pkg.PackageBase.Popularity | number_format(2) }}
{{ pkg.Popularity | number_format(2) }}
</td>
{% if request.user.is_authenticated() %}
<td>
{% if pkg.PackageBase.ID in voted %}
{% if pkg.Voted %}
{{ "Yes" | tr }}
{% endif %}
</td>
<td>
{% if pkg.PackageBase.ID in notified %}
{% if pkg.Notify %}
{{ "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 }}
{% if pkg.Maintainer %}
<a href="/account/{{ pkg.Maintainer }}">
{{ pkg.Maintainer }}
</a>
{% else %}
<span class="error">{{ "orphan" | tr }}</span>