From 145b1138d732b9501b368e21ab1bc4bc873a632b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 27 May 2026 17:18:10 +0200 Subject: [PATCH] v0.0.642 Fix wmo createPaginationPipeline not sorting on initial token --- goextVersion.go | 4 ++-- wmo/queryList.go | 28 ++++++++++++---------------- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index df583fc..f6fc23f 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.641" +const GoextVersion = "0.0.642" -const GoextVersionTimestamp = "2026-05-22T22:06:05+0200" +const GoextVersionTimestamp = "2026-05-27T17:18:10+0200" diff --git a/wmo/queryList.go b/wmo/queryList.go index 74c211e..8d24b46 100644 --- a/wmo/queryList.go +++ b/wmo/queryList.go @@ -402,17 +402,17 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CTKeySort, } if isValidTokenValue(valuePrimary) { - if sortPrimary == ct.SortASC { - // We sort ASC on - so we want all entries newer ($gt) than the $primary - cond = append(cond, bson.M{fieldPrimary: bson.M{"$gt": valuePrimary}}) - sort = append(sort, bson.E{Key: fieldPrimary, Value: +1}) + cond = append(cond, bson.M{fieldPrimary: bson.M{"$gt": valuePrimary}}) // We sort ASC on - so we want all entries newer ($gt) than the $primary } else if sortPrimary == ct.SortDESC { - // We sort DESC on - so we want all entries older ($lt) than the $primary - cond = append(cond, bson.M{fieldPrimary: bson.M{"$lt": valuePrimary}}) - sort = append(sort, bson.E{Key: fieldPrimary, Value: -1}) + cond = append(cond, bson.M{fieldPrimary: bson.M{"$lt": valuePrimary}}) // We sort DESC on - so we want all entries older ($lt) than the $primary } + } + if sortPrimary == ct.SortASC { + sort = append(sort, bson.E{Key: fieldPrimary, Value: +1}) // We sort ASC on - so we want all entries newer ($gt) than the $primary + } else if sortPrimary == ct.SortDESC { + sort = append(sort, bson.E{Key: fieldPrimary, Value: -1}) // We sort DESC on - so we want all entries older ($lt) than the $primary } if fieldSecondary != nil && sortSecondary != nil && *fieldSecondary != fieldPrimary { @@ -423,29 +423,25 @@ func createPaginationPipeline[TData any](coll *Coll[TData], token ct.CTKeySort, } if isValidTokenValue(valueSecondary) { - if *sortSecondary == ct.SortASC { - // the conflict-resolution condition, for entries with the _same_ as the $primary we take the ones with a greater $secondary (= newer) cond = append(cond, bson.M{"$and": bson.A{ bson.M{"$or": bson.A{bson.M{fieldPrimary: valuePrimary}, bson.M{fieldPrimary: nil}, bson.M{fieldPrimary: bson.M{"$exists": false}}}}, bson.M{*fieldSecondary: bson.M{"$gt": valueSecondary}}, }}) - - sort = append(sort, bson.E{Key: *fieldSecondary, Value: +1}) - } else if *sortSecondary == ct.SortDESC { - // the conflict-resolution condition, for entries with the _same_ as the $primary we take the ones with a smaller $secondary (= older) cond = append(cond, bson.M{"$and": bson.A{ bson.M{"$or": bson.A{bson.M{fieldPrimary: valuePrimary}, bson.M{fieldPrimary: nil}, bson.M{fieldPrimary: bson.M{"$exists": false}}}}, bson.M{*fieldSecondary: bson.M{"$lt": valueSecondary}}, }}) - - sort = append(sort, bson.E{Key: *fieldSecondary, Value: -1}) - } + } + if *sortSecondary == ct.SortASC { + sort = append(sort, bson.E{Key: *fieldSecondary, Value: +1}) + } else if *sortSecondary == ct.SortDESC { + sort = append(sort, bson.E{Key: *fieldSecondary, Value: -1}) } }