mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
perf: improve packages search-query
Improves performance for queries with large result sets. The "group by" clause can be removed for all search types but the keywords. Signed-off-by: moson-mo <mo-son@mailbox.org>
This commit is contained in:
parent
d8e91d058c
commit
7a9448a3e5
3 changed files with 33 additions and 17 deletions
|
@ -136,7 +136,10 @@ class PackageSearch:
|
|||
self._join_user()
|
||||
self._join_keywords()
|
||||
keywords = set(k.lower() for k in keywords)
|
||||
self.query = self.query.filter(PackageKeyword.Keyword.in_(keywords))
|
||||
self.query = self.query.filter(PackageKeyword.Keyword.in_(keywords)).group_by(
|
||||
models.Package.Name
|
||||
)
|
||||
|
||||
return self
|
||||
|
||||
def _search_by_maintainer(self, keywords: str) -> orm.Query:
|
||||
|
|
|
@ -93,22 +93,18 @@ async def packages_get(
|
|||
search.sort_by(sort_by, sort_order)
|
||||
|
||||
# Insert search results into the context.
|
||||
results = (
|
||||
search.results()
|
||||
.with_entities(
|
||||
models.Package.ID,
|
||||
models.Package.Name,
|
||||
models.Package.PackageBaseID,
|
||||
models.Package.Version,
|
||||
models.Package.Description,
|
||||
models.PackageBase.Popularity,
|
||||
models.PackageBase.NumVotes,
|
||||
models.PackageBase.OutOfDateTS,
|
||||
models.User.Username.label("Maintainer"),
|
||||
models.PackageVote.PackageBaseID.label("Voted"),
|
||||
models.PackageNotification.PackageBaseID.label("Notify"),
|
||||
)
|
||||
.group_by(models.Package.Name)
|
||||
results = search.results().with_entities(
|
||||
models.Package.ID,
|
||||
models.Package.Name,
|
||||
models.Package.PackageBaseID,
|
||||
models.Package.Version,
|
||||
models.Package.Description,
|
||||
models.PackageBase.Popularity,
|
||||
models.PackageBase.NumVotes,
|
||||
models.PackageBase.OutOfDateTS,
|
||||
models.User.Username.label("Maintainer"),
|
||||
models.PackageVote.PackageBaseID.label("Voted"),
|
||||
models.PackageNotification.PackageBaseID.label("Notify"),
|
||||
)
|
||||
|
||||
packages = results.limit(per_page).offset(offset)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue