Skip to content

fix(graph): list the tags in use sorted and cut at a fixed limit - #3891

Merged
pbleser-oc merged 2 commits into
opencloud-eu:mainfrom
pbleser-oc:fix/3889-get-tags-sorted-limit
Nov 18, 2026
Merged

pbleser-oc merged 2 commits into
opencloud-eu:mainfrom
pbleser-oc:fix/3889-get-tags-sorted-limit

Conversation

@pbleser-oc

@pbleser-oc pbleser-oc commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

GET /graph/v1.0/extensions/org.libregraph/tags now returns the distinct tags in use, sorted in byte order, and at most 100 of them. Before, it returned an arbitrary 100 tags in an unstable order once more than 100 were in use.

Fixes #3889

Details:

  • GetTags collected the tags of all search results into a tags.Tags object. That type is meant for a single resource: it stops accepting tags at 100 and puts new tags in front. So which 100 tags were returned, and their order, depended on the order of the search results.
  • The tags are now collected into a set, sorted in byte order, and cut at the documented constant maxListedTags (100).
  • Byte order on purpose: upper case comes before lower case ("Banana" before "apple"). It is the order in which search engines sort keyword values, so the search can later return just the first tags of every space (search: listing all tags transfers every tagged resource from the search engine #3890), and merging those lists still gives exactly the first 100 overall. A case-insensitive order would need an aggregation on a lowercased copy of the field: a mapping change, a reindex, and the original casing lost. The order is not meant for display: the web client currently shows the tags in the order it receives them, so it needs to sort them in the user's language, see Tag lists are shown in the server's order instead of being sorted for display web#4248. Ideally both land around the same time.
  • The response format stays the same, including {"value": []} when no tags are in use.
  • Limitation: the result is only fully deterministic when the search returns every tagged resource, as the bleve engine does. With OpenSearch, a search for all results stops at 1000 hits per space, so tags that only occur on other resources are missing, and which hits are returned is up to OpenSearch. search: listing all tags transfers every tagged resource from the search engine #3890 is about letting the search engines aggregate the tags, which closes that gap.

Tests: new tags_test.go covering deduplication, the sort order, a stable result regardless of the search order, the cut at the limit, the empty response and a failing search. The tests for the order and the limit fail without the fix.

AI assistance: Claude Code (claude-opus-5-5) wrote the fix and the tests.

@codacy-production

codacy-production Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 16 complexity

Metric Results
Complexity 16

View in Codacy

🟢 Coverage 100.00% diff coverage · +0.03% coverage variation

Metric Results
Coverage variation ✅ +0.03% coverage variation (-1.00%)
Diff coverage ✅ 100.00% diff coverage

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (f8a8ecf) 94293 28310 30.02%
Head commit (7ed534d) 94298 (+5) 28344 (+34) 30.06% (+0.03%)

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#3891) 11 11 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

GetTags collected the tags of all search results into a tags.Tags
object, which is meant for the tags of a single resource: it stops
accepting tags at 100 and puts new tags in front. So when more than 100
distinct tags were in use, the response held an arbitrary 100 of them,
and the order changed with the order of the search results.

Collect the distinct tags, sort them case-insensitively (ties in byte
order), and cut the list at the documented constant maxListedTags (100).
An empty list is still rendered as "value": [].

Fixes opencloud-eu#3889

Assisted-by: Claude Code:claude-opus-5-5
Expect(getTags()).To(Equal([]string{"draft", "work"}))
})

It("sorts the tags in byte order, upper case before lower case", func() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Small thing: this spec also passes against main. The input {"cherry","apple"}, {"Banana","Apple"} is in reverse sorted order, and the old tags.Tags puts each new batch in front, so it ends up sorted by chance. With e.g. {"apple","cherry"}, {"Apple","Banana"} it fails without the fix and really pins down the sorting.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thanks, good catch. The old input came out sorted by chance. With yours, the spec fails on main and passes with the fix.

@pbleser-oc
pbleser-oc force-pushed the fix/3889-get-tags-sorted-limit branch from 888fe78 to 77f127c Compare November 18, 2026 10:21

@asaah262 asaah262 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks, this makes the tag list deterministic, and the reasoning for byte order in the doc comment is very helpful. I checked it locally: the graph service tests pass, also with -race. Against main's handler, the "stable order" and "limit" specs fail as expected. One small nit: the byte-order spec passes without the fix (see inline). Otherwise LGTM.

Byte order is the order in which search engines sort keyword values,
e.g. an OpenSearch terms aggregation ordered by key. With the same
order, the search can return just the first tags of every space, and
merging those lists still gives exactly the first tags overall. A
case-insensitive order would need an aggregation on a lowercased copy
of the field, with a mapping change, a reindex and the loss of the
original casing.

Assisted-by: Claude Code:claude-opus-5-5
@pbleser-oc
pbleser-oc force-pushed the fix/3889-get-tags-sorted-limit branch from 77f127c to 7ed534d Compare November 18, 2026 10:29
@pbleser-oc
pbleser-oc merged commit e6c2215 into opencloud-eu:main Nov 18, 2026
61 checks passed
@pbleser-oc
pbleser-oc deleted the fix/3889-get-tags-sorted-limit branch November 18, 2026 18:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

graph: GET /extensions/org.libregraph/tags returns an arbitrary, unstably ordered subset of 100 tags

2 participants