Repository navigation
fix(graph): list the tags in use sorted and cut at a fixed limit - #3891
Conversation
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 16 |
🟢 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 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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Thanks, good catch. The old input came out sorted by chance. With yours, the spec fails on main and passes with the fix.
888fe78 to
77f127c
Compare
asaah262
left a comment
There was a problem hiding this comment.
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
77f127c to
7ed534d
Compare
GET /graph/v1.0/extensions/org.libregraph/tagsnow 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:
GetTagscollected the tags of all search results into atags.Tagsobject. 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.maxListedTags(100).{"value": []}when no tags are in use.Tests: new
tags_test.gocovering 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.