From 25b6f41467c409eb7f5fe60d3c91057e161bd151 Mon Sep 17 00:00:00 2001 From: Pavel Ivanov Date: Tue, 12 Nov 2024 01:32:09 +0500 Subject: [PATCH] rkey: scan - order by id (#35) --- internal/rkey/tx.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/rkey/tx.go b/internal/rkey/tx.go index c031dd8..4dc93f5 100644 --- a/internal/rkey/tx.go +++ b/internal/rkey/tx.go @@ -84,6 +84,7 @@ const ( where id > ? and key glob ? and (type = ? or true) and (etime is null or etime > ?) + order by id asc limit ?` ) @@ -347,10 +348,8 @@ func (tx *Tx) Scan(cursor int, pattern string, ktype core.TypeID, count int) (Sc // Select the maximum ID. maxID := 0 - for _, key := range keys { - if key.ID > maxID { - maxID = key.ID - } + if len(keys) > 0 { + maxID = keys[len(keys)-1].ID } return ScanResult{maxID, keys}, nil