forked from TrueCloudLab/frostfs-s3-gw
[#112] api: Refactor allObjectsParams struct
Replaced Bucket (means name) by BucketInfo struct Signed-off-by: Angira Kekteeva <kira@nspcc.ru>
This commit is contained in:
parent
65cd1db56d
commit
97a7d16f68
1 changed files with 16 additions and 9 deletions
|
@ -55,7 +55,7 @@ type (
|
||||||
}
|
}
|
||||||
|
|
||||||
allObjectParams struct {
|
allObjectParams struct {
|
||||||
Bucket string
|
Bucket *BucketInfo
|
||||||
Delimiter string
|
Delimiter string
|
||||||
Prefix string
|
Prefix string
|
||||||
StartAfter string
|
StartAfter string
|
||||||
|
@ -210,14 +210,19 @@ func (n *layer) ListObjectsV1(ctx context.Context, p *ListObjectsParamsV1) (*Lis
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
result ListObjectsInfoV1
|
result ListObjectsInfoV1
|
||||||
|
bkt *BucketInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
if p.MaxKeys == 0 {
|
if p.MaxKeys == 0 {
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
allObjects, err := n.listSortedAllObjects(ctx, allObjectParams{
|
allObjects, err := n.listSortedAllObjects(ctx, allObjectParams{
|
||||||
Bucket: p.Bucket,
|
Bucket: bkt,
|
||||||
Prefix: p.Prefix,
|
Prefix: p.Prefix,
|
||||||
Delimiter: p.Delimiter,
|
Delimiter: p.Delimiter,
|
||||||
StartAfter: p.Marker,
|
StartAfter: p.Marker,
|
||||||
|
@ -252,17 +257,22 @@ func (n *layer) ListObjectsV2(ctx context.Context, p *ListObjectsParamsV2) (*Lis
|
||||||
err error
|
err error
|
||||||
result ListObjectsInfoV2
|
result ListObjectsInfoV2
|
||||||
allObjects []*ObjectInfo
|
allObjects []*ObjectInfo
|
||||||
|
bkt *BucketInfo
|
||||||
)
|
)
|
||||||
|
|
||||||
if p.MaxKeys == 0 {
|
if p.MaxKeys == 0 {
|
||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
if p.ContinuationToken != "" {
|
if p.ContinuationToken != "" {
|
||||||
// find cache with continuation token
|
// find cache with continuation token
|
||||||
} else {
|
} else {
|
||||||
allObjects, err = n.listSortedAllObjects(ctx, allObjectParams{
|
allObjects, err = n.listSortedAllObjects(ctx, allObjectParams{
|
||||||
Bucket: p.Bucket,
|
Bucket: bkt,
|
||||||
Prefix: p.Prefix,
|
Prefix: p.Prefix,
|
||||||
Delimiter: p.Delimiter,
|
Delimiter: p.Delimiter,
|
||||||
StartAfter: p.StartAfter,
|
StartAfter: p.StartAfter,
|
||||||
|
@ -292,14 +302,11 @@ func (n *layer) ListObjectsV2(ctx context.Context, p *ListObjectsParamsV2) (*Lis
|
||||||
func (n *layer) listSortedAllObjects(ctx context.Context, p allObjectParams) ([]*ObjectInfo, error) {
|
func (n *layer) listSortedAllObjects(ctx context.Context, p allObjectParams) ([]*ObjectInfo, error) {
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
bkt *BucketInfo
|
|
||||||
ids []*object.ID
|
ids []*object.ID
|
||||||
uniqNames = make(map[string]bool)
|
uniqNames = make(map[string]bool)
|
||||||
)
|
)
|
||||||
|
|
||||||
if bkt, err = n.GetBucketInfo(ctx, p.Bucket); err != nil {
|
if ids, err = n.objectSearch(ctx, &findParams{cid: p.Bucket.CID}); err != nil {
|
||||||
return nil, err
|
|
||||||
} else if ids, err = n.objectSearch(ctx, &findParams{cid: bkt.CID}); err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -308,14 +315,14 @@ func (n *layer) listSortedAllObjects(ctx context.Context, p allObjectParams) ([]
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
addr := object.NewAddress()
|
addr := object.NewAddress()
|
||||||
addr.SetObjectID(id)
|
addr.SetObjectID(id)
|
||||||
addr.SetContainerID(bkt.CID)
|
addr.SetContainerID(p.Bucket.CID)
|
||||||
|
|
||||||
meta, err := n.objectHead(ctx, addr)
|
meta, err := n.objectHead(ctx, addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
n.log.Warn("could not fetch object meta", zap.Error(err))
|
n.log.Warn("could not fetch object meta", zap.Error(err))
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if oi := objectInfoFromMeta(bkt, meta, p.Prefix, p.Delimiter); oi != nil {
|
if oi := objectInfoFromMeta(p.Bucket, meta, p.Prefix, p.Delimiter); oi != nil {
|
||||||
// use only unique dir names
|
// use only unique dir names
|
||||||
if _, ok := uniqNames[oi.Name]; ok {
|
if _, ok := uniqNames[oi.Name]; ok {
|
||||||
continue
|
continue
|
||||||
|
|
Loading…
Reference in a new issue