fix: remove /packages search count limit

...took this opportunity to use the new options.max_search_results
tunable for a PP upper-bound.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2022-02-06 16:11:54 -08:00
parent 1545eab81d
commit 750653361f
No known key found for this signature in database
GPG key ID: F7E46DED420788F3
2 changed files with 8 additions and 11 deletions

View file

@ -222,14 +222,9 @@ class PackageSearch:
ordering = self.FULL_SORT_ORDER.get(ordering)
return callback(ordering)
def count(self, limit: int) -> int:
"""
Return internal query's count up to `limit`.
:param limit: Upper bound
:return: Database count up to `limit`
"""
return self.query.limit(limit).count()
def count(self) -> int:
""" Return internal query's count. """
return self.query.count()
def results(self) -> orm.Query:
""" Return internal query. """

View file

@ -31,7 +31,10 @@ async def packages_get(request: Request, context: Dict[str, Any],
request.query_params.get("O", defaults.O),
request.query_params.get("PP", defaults.PP))
context["O"] = offset
context["PP"] = per_page
# Limit PP to options.max_search_results
max_search_results = aurweb.config.getint("options", "max_search_results")
context["PP"] = per_page = min(per_page, max_search_results)
# Query search by.
search_by = context["SeB"] = request.query_params.get("SeB", "nd")
@ -56,8 +59,7 @@ async def packages_get(request: Request, context: Dict[str, Any],
# 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.
limit = config.getint("options", "max_search_results")
num_packages = search.count(limit)
num_packages = search.count()
flagged = request.query_params.get("outdated", None)
if flagged: