Skip to content

Commit b7e7659

Browse files
authored
the latest created flavor will now be first in the list (#126)
this is, so we have a consistent ordering and behavior, as flavor versions are sorted the same way.
1 parent 998e934 commit b7e7659

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

controlplane/postgres/chunk.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ func collectChunks(rows []chunkRelationsRow) chunk.Chunk {
326326

327327
for _, f := range flavorMap {
328328
sort.Slice(f.Versions, func(i, j int) bool {
329+
// the latest flavor version will be the first entry in the slice
329330
return f.Versions[i].CreatedAt.Before(f.Versions[j].CreatedAt)
330331
})
331332
for _, v := range f.Versions {
@@ -336,6 +337,11 @@ func collectChunks(rows []chunkRelationsRow) chunk.Chunk {
336337
}
337338

338339
c.Flavors = slices.Collect(maps.Values(flavorMap))
340+
sort.Slice(c.Flavors, func(i, j int) bool {
341+
// the latest flavor will be the first entry in the slice
342+
return c.Flavors[i].CreatedAt.Before(c.Flavors[j].CreatedAt)
343+
})
344+
339345
ret = c
340346

341347
return ret

test/fixture/chunk.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@ func Chunk(mod ...func(c *chunk.Chunk)) chunk.Chunk {
4646
Description: "some description bla bla",
4747
Tags: []string{"tag1", "tag2"},
4848
Flavors: []chunk.Flavor{
49-
Flavor(func(f *chunk.Flavor) {
50-
f.ID = "01953e68-4ca6-73b1-89b4-86455ffd78e7"
51-
f.Name = "flavor1"
52-
}),
49+
// the latest flavor has to be first
5350
Flavor(func(f *chunk.Flavor) {
5451
f.ID = "01953e68-8313-76ba-8012-2f51abb7988a"
5552
f.Name = "flavor2"
53+
f.CreatedAt = time.Date(2025, 2, 23, 13, 12, 15, 0, time.UTC)
54+
}),
55+
Flavor(func(f *chunk.Flavor) {
56+
f.ID = "01953e68-4ca6-73b1-89b4-86455ffd78e7"
57+
f.Name = "flavor1"
58+
f.CreatedAt = time.Date(2024, 2, 23, 13, 12, 15, 0, time.UTC)
5659
}),
5760
},
5861
CreatedAt: time.Date(2025, 2, 23, 13, 12, 15, 0, time.UTC),

0 commit comments

Comments
 (0)