Revert "fix: unified resource server list queries order column" (#109529)
This commit is contained in:
@@ -215,6 +215,7 @@ func (k *kvStorageBackend) ListIterator(ctx context.Context, req *resourcepb.Lis
|
||||
|
||||
// Fetch the latest objects
|
||||
keys := make([]MetaDataKey, 0, min(defaultListBufferSize, req.Limit+1))
|
||||
idx := 0
|
||||
for metaKey, err := range k.metaStore.ListResourceKeysAtRevision(ctx, MetaListRequestKey{
|
||||
Namespace: req.Options.Key.Namespace,
|
||||
Group: req.Options.Key.Group,
|
||||
@@ -224,15 +225,17 @@ func (k *kvStorageBackend) ListIterator(ctx context.Context, req *resourcepb.Lis
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
// Skip the first offset items. This is not efficient, but it's a simple way to implement it for now.
|
||||
if idx < int(offset) {
|
||||
idx++
|
||||
continue
|
||||
}
|
||||
keys = append(keys, metaKey)
|
||||
// Only fetch the first limit items + 1 to get the next token.
|
||||
if len(keys) >= int(req.Limit+1) {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
sortMetaKeysByResourceVersion(keys, true) // sort ascending for sql parity
|
||||
|
||||
if offset > 0 && int64(len(keys)) > offset {
|
||||
keys = keys[offset:]
|
||||
}
|
||||
|
||||
iter := kvListIterator{
|
||||
keys: keys,
|
||||
currentIndex: -1,
|
||||
@@ -430,19 +433,6 @@ func sortByResourceVersion(filteredKeys []DataKey, sortAscending bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// sortMetaKeysByResourceVersion sorts the metadata keys based on the sortAscending flag
|
||||
func sortMetaKeysByResourceVersion(keys []MetaDataKey, sortAscending bool) {
|
||||
if sortAscending {
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
return keys[i].ResourceVersion < keys[j].ResourceVersion
|
||||
})
|
||||
} else {
|
||||
sort.Slice(keys, func(i, j int) bool {
|
||||
return keys[i].ResourceVersion > keys[j].ResourceVersion
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// applyPagination filters keys based on pagination parameters
|
||||
func applyPagination(keys []DataKey, lastSeenRV int64, sortAscending bool) []DataKey {
|
||||
if lastSeenRV == 0 {
|
||||
|
||||
Reference in New Issue
Block a user