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

@ -200,7 +200,7 @@ def query_voted(query: List[models.Package],
:return: Vote state dict (PackageBase.ID: int -> bool)
"""
output = defaultdict(bool)
query_set = {pkg.PackageBase.ID for pkg in query}
query_set = {pkg.PackageBaseID for pkg in query}
voted = db.query(models.PackageVote).join(
models.PackageBase,
models.PackageBase.ID.in_(query_set)
@ -223,7 +223,7 @@ def query_notified(query: List[models.Package],
:return: Notification state dict (PackageBase.ID: int -> bool)
"""
output = defaultdict(bool)
query_set = {pkg.PackageBase.ID for pkg in query}
query_set = {pkg.PackageBaseID for pkg in query}
notified = db.query(models.PackageNotification).join(
models.PackageBase,
models.PackageBase.ID.in_(query_set)