forked from TrueCloudLab/frostfs-node
[#1070] pilorama: Fix cycling behaviour for sorted listing
In case there are no items left, return empty slice. Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
parent
4080b99310
commit
17af91619a
1 changed files with 13 additions and 9 deletions
|
@ -1069,15 +1069,7 @@ func (t *boltForest) TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, tr
|
||||||
}
|
}
|
||||||
|
|
||||||
if fewChildren {
|
if fewChildren {
|
||||||
sort.Slice(result, func(i, j int) bool {
|
result = sortAndCut(result, []byte(last))
|
||||||
return bytes.Compare(result[i].Meta.GetAttr(AttributeFilename), result[j].Meta.GetAttr(AttributeFilename)) == -1
|
|
||||||
})
|
|
||||||
for i := range result {
|
|
||||||
if bytes.Compare([]byte(last), result[i].Meta.GetAttr(AttributeFilename)) == -1 {
|
|
||||||
result = result[i:]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if len(result) != 0 {
|
if len(result) != 0 {
|
||||||
last = string(result[len(result)-1].Meta.GetAttr(AttributeFilename))
|
last = string(result[len(result)-1].Meta.GetAttr(AttributeFilename))
|
||||||
|
@ -1085,6 +1077,18 @@ func (t *boltForest) TreeSortedByFilename(ctx context.Context, cid cidSDK.ID, tr
|
||||||
return result, last, metaerr.Wrap(err)
|
return result, last, metaerr.Wrap(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sortAndCut(result []NodeInfo, last []byte) []NodeInfo {
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
return bytes.Compare(result[i].Meta.GetAttr(AttributeFilename), result[j].Meta.GetAttr(AttributeFilename)) == -1
|
||||||
|
})
|
||||||
|
for i := range result {
|
||||||
|
if bytes.Compare(last, result[i].Meta.GetAttr(AttributeFilename)) == -1 {
|
||||||
|
return result[i:]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (t *boltForest) getChildInfo(b *bbolt.Bucket, key []byte, childID Node) (NodeInfo, error) {
|
func (t *boltForest) getChildInfo(b *bbolt.Bucket, key []byte, childID Node) (NodeInfo, error) {
|
||||||
childInfo := NodeInfo{ID: childID}
|
childInfo := NodeInfo{ID: childID}
|
||||||
parentID, _, metaBytes, found := t.getState(b, stateKey(key, childID))
|
parentID, _, metaBytes, found := t.getState(b, stateKey(key, childID))
|
||||||
|
|
Loading…
Reference in a new issue