fix: /packages search result count

We need to query for this after we've applied all filters.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-02-17 17:42:24 -08:00
parent bfd592299c
commit dcaf407536
No known key found for this signature in database
GPG key ID: F7E46DED420788F3

View file

@ -61,11 +61,6 @@ async def packages_get(request: Request, context: Dict[str, Any],
for keyword in keywords: for keyword in keywords:
search.search_by(search_by, keyword) search.search_by(search_by, keyword)
# Collect search result count here; we've applied our keywords.
# Including more query operations below, like ordering, will
# increase the amount of time required to collect a count.
num_packages = search.count()
flagged = request.query_params.get("outdated", None) flagged = request.query_params.get("outdated", None)
if flagged: if flagged:
# If outdated was given, set it up in the context. # If outdated was given, set it up in the context.
@ -90,7 +85,12 @@ async def packages_get(request: Request, context: Dict[str, Any],
search.query = search.query.filter( search.query = search.query.filter(
models.PackageBase.MaintainerUID.is_(None)) models.PackageBase.MaintainerUID.is_(None))
# Apply user-specified specified sort column and ordering. # Collect search result count here; we've applied our keywords.
# Including more query operations below, like ordering, will
# increase the amount of time required to collect a count.
num_packages = search.count()
# Apply user-specified sort column and ordering.
search.sort_by(sort_by, sort_order) search.sort_by(sort_by, sort_order)
# Insert search results into the context. # Insert search results into the context.