Fix: Queried category should appear first in post category list when filtering by category#8373
Fix: Queried category should appear first in post category list when filtering by category#8373
Conversation
|
|
…gory Co-authored-by: ruibaby <21301288+ruibaby@users.noreply.github.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|



When a post belongs to multiple categories and a visitor filters posts by a specific category, the post card displays a random category name instead of the one being filtered — because the backend returns all post categories in stored order and templates display the first one.
Changes
PostFinderImpl.listByCategory(): After fetching posts, reorder each post'scategorieslist so the queried category appears first, followed by matched child categories, then remaining categories.PostFinderImpl.list(Map params): Same fix applied whencategoryNamefilter is present.sortCategoriesByFilter()helper: Extracted shared sorting logic; usesHashSetfor O(n log n) sort instead of O(n²·m).ListByCategoryTestcovering multi-category reordering and single-category no-op cases.What type of PR is this?
/kind bug
/kind regression
What this PR does / why we need it:
When filtering posts by category on the visitor-facing site, each post's
categorieslist was returned in stored order. Since templates display the first category, a post with["cat2", "cat1"]filtered bycat1would showcat2on the card. The fix reorders categories per-post so the filtered category is always first.Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
The reordering is applied only in the two category-filtered list paths (
listByCategoryandlist(Map)withcategoryName). Other listing paths (by tag, owner, archives) are unaffected.Does this PR introduce a user-facing change?
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/opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/tools/linux64/java/bin/java -jar /opt/hostedtoolcache/CodeQL/2.24.2/x64/codeql/xml/tools/xml-extractor.jar --fileList=/tmp/codeql-scratch-dd1d0a2b113c8104/dbs/java/working/files-to-index3278415875141933549.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:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.