Skip to content

Commit

Permalink
[nspcc-dev#112] api: Add start-after to ListObjectsV2 cache
Browse files Browse the repository at this point in the history
In case when we send a response from a cache

Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
  • Loading branch information
masterSplinter01 committed Jul 27, 2021
1 parent a95687e commit d09b399
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions api/layer/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ func (n *layer) ListObjectsV2(ctx context.Context, p *ListObjectsParamsV2) (*Lis

if p.ContinuationToken != "" {
allObjects = n.cache.GetCache(p.ContinuationToken, cacheKey)
allObjects = trimStartAfter(p.StartAfter, allObjects)
}

if allObjects == nil {
Expand Down Expand Up @@ -369,3 +370,14 @@ func (n *layer) listSortedAllObjects(ctx context.Context, p allObjectParams) ([]

return objects, nil
}

func trimStartAfter(startAfter string, objects []*ObjectInfo) []*ObjectInfo {
if objects != nil && len(startAfter) != 0 && objects[0].Name <= startAfter {
for i, _ := range objects {
if objects[i].Name > startAfter {
return objects[i:]
}
}
}
return objects
}

0 comments on commit d09b399

Please sign in to comment.