commit b8b412d0cee2fe92f4493fde95964f87f7966860
parent 5876e85b587714065a4d56cb696ae072e26ae1b3
Author: Sean Enck <sean@ttypty.com>
Date: Fri, 16 Aug 2024 21:50:25 -0400
sort slice as the entities are processed
Diffstat:
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/internal/backend/query.go b/internal/backend/query.go
@@ -152,7 +152,15 @@ func (t *Transaction) QueryCallback(args QueryOptions) (QuerySeq2, error) {
}
}
}
- entities = append(entities, QueryEntity{backing: entry, Path: path})
+ obj := QueryEntity{backing: entry, Path: path}
+ if isSort && len(entities) > 0 {
+ i, _ := slices.BinarySearchFunc(entities, obj, func(i, j QueryEntity) int {
+ return strings.Compare(i.Path, j.Path)
+ })
+ entities = slices.Insert(entities, i, obj)
+ } else {
+ entities = append(entities, obj)
+ }
})
if decrypt {
return ctx.db.UnlockProtectedEntries()
@@ -162,11 +170,6 @@ func (t *Transaction) QueryCallback(args QueryOptions) (QuerySeq2, error) {
if err != nil {
return nil, err
}
- if isSort {
- slices.SortFunc(entities, func(i, j QueryEntity) int {
- return strings.Compare(i.Path, j.Path)
- })
- }
jsonMode := config.JSONOutputs.Blank
if args.Values == JSONValue {
m, err := config.ParseJSONOutput()