Skip to content

fix: maintain input order in categoryFinder.getByNames and tagFinder.getByNames#9882

Merged
JohnNiang merged 5 commits into
mainfrom
copilot/fix-categoryfinder-order-issue
Apr 15, 2026
Merged

fix: maintain input order in categoryFinder.getByNames and tagFinder.getByNames#9882
JohnNiang merged 5 commits into
mainfrom
copilot/fix-categoryfinder-order-issue

Conversation

Copilot AI commented Apr 13, 2026

Copy link
Copy Markdown
Contributor

getByNames in both CategoryFinderImpl and TagFinderImpl returned results sorted by the store's default sort (priority/creationTimestamp/name) rather than preserving the caller-provided names order.

Changes:

  • After fetching matched items via Queries.in(...), collect results and re-sort using a pre-built HashMap<name → index> derived from the input collection — O(n log n), avoids repeated indexOf scans
  • Applied identically to CategoryFinderImpl.getByNames and TagFinderImpl.getByNames
  • Added tests to both CategoryFinderImplTest and TagFinderImplTest verifying order is preserved when the store returns items in a different order than requested
// Before: returned [category-bar, category-foo] despite input order
categoryFinder.getByNames(List.of("category-foo", "category-bar"))

// After: returns [category-foo, category-bar] matching input order

What type of PR is this?

/kind bug

What this PR does / why we need it:

getByNames in CategoryFinderImpl and TagFinderImpl ignored the order of the input names collection, returning results sorted by the store's default comparator instead. This fix post-sorts results using a name→index map built from the input, preserving caller-specified order.

Which issue(s) this PR fixes:

Special notes for your reviewer:

The same bug existed in TagFinderImpl.getByNames and is fixed in the same commit.

Does this PR introduce a user-facing change?

修复通过 `categoryFinder.getByNames` 和 `tagFinder.getByNames` 获取的结果顺序不对的问题

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkstyle.org
    • Triggering command: /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.25.1/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/working/files-to-index12714299948922818648.list --sourceArchiveDir=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/src --outputDir=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/trap/java (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

@f2c-ci-robot f2c-ci-robot Bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 13, 2026
Copilot AI linked an issue Apr 13, 2026 that may be closed by this pull request
4 tasks
@f2c-ci-robot f2c-ci-robot Bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Apr 13, 2026
@CLAassistant

CLAassistant commented Apr 13, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ JohnNiang
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

@f2c-ci-robot

f2c-ci-robot Bot commented Apr 13, 2026

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from ruibaby. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI changed the title [WIP] Fix categoryFinder.getByNames to maintain order of names array fix: maintain input order in categoryFinder.getByNames and tagFinder.getByNames Apr 13, 2026
@f2c-ci-robot f2c-ci-robot Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Apr 13, 2026
Copilot AI requested a review from ruibaby April 13, 2026 10:57
@ruibaby ruibaby marked this pull request as ready for review April 14, 2026 04:59
@f2c-ci-robot f2c-ci-robot Bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Apr 14, 2026

@ruibaby ruibaby left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/lgtm

@f2c-ci-robot f2c-ci-robot Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 14, 2026
@f2c-ci-robot f2c-ci-robot Bot removed the lgtm Indicates that a PR is ready to be merged. label Apr 14, 2026
@f2c-ci-robot

f2c-ci-robot Bot commented Apr 14, 2026

Copy link
Copy Markdown

New changes are detected. LGTM label has been removed.

@sonarqubecloud

Copy link
Copy Markdown

@JohnNiang JohnNiang merged commit 5096079 into main Apr 15, 2026
9 of 11 checks passed
@ruibaby ruibaby modified the milestones: 2.24.x, 2.24.0 Apr 15, 2026
@JohnNiang JohnNiang deleted the copilot/fix-categoryfinder-order-issue branch April 17, 2026 05:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note Denotes a PR that will be considered when it comes time to generate release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

categoryFinder.getByNames doesn't maintain the order of the names array

4 participants