Skip to content

Commit 63f1627

Browse files
[repo-assist] perf(query): normalize search terms once per query (#2928)
perf(query): normalize search terms once per query Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f7c3643 commit 63f1627

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

pkg/query/query_builder.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,12 @@ func (s *SourceQueryBuilder) Execute(ctx context.Context, dbExecutor db.Executor
235235
var aurResults []aur.Pkg
236236
aurResults, aurErr = queryAUR(ctx, s.aurClient, pkgS, s.searchBy)
237237
dbName := "aur"
238+
searchTerms := normalizeSearchTerms(pkgS)
238239

239240
for i := range aurResults {
240241
by := getSearchBy(s.searchBy)
241242
if (by == aur.NameDesc || by == aur.None || by == aur.Name) &&
242-
!matchesSearch(&aurResults[i], pkgS) {
243+
!matchesSearch(&aurResults[i], searchTerms) {
243244
continue
244245
}
245246

@@ -332,6 +333,14 @@ func (s *SourceQueryBuilder) GetTargets(include, exclude intrange.IntRanges,
332333
return targets, nil
333334
}
334335

336+
func normalizeSearchTerms(terms []string) []string {
337+
normalized := make([]string, len(terms))
338+
for i, term := range terms {
339+
normalized[i] = strings.ToLower(term)
340+
}
341+
return normalized
342+
}
343+
335344
func matchesSearch(pkg *aur.Pkg, terms []string) bool {
336345
if len(terms) <= 1 {
337346
return true
@@ -344,9 +353,7 @@ func matchesSearch(pkg *aur.Pkg, terms []string) bool {
344353
continue
345354
}
346355

347-
targ := strings.ToLower(pkgN)
348-
349-
if !strings.Contains(name, targ) && !strings.Contains(desc, targ) {
356+
if !strings.Contains(name, pkgN) && !strings.Contains(desc, pkgN) {
350357
return false
351358
}
352359
}

0 commit comments

Comments
 (0)