[#xx] metabase: Refactor selectNFromBucket

The function is riskly long. so adding just a few lines of code
might trigger the `funlen` linter. Kept the changes minimal:
- Moved the logic for filling object info into a separate function
- Preserved all existing side effects

Signed-off-by: Aleksey Savchuk <a.savchuk@yadro.com>
This commit is contained in:
Aleksey Savchuk 2024-12-25 21:49:17 +03:00
parent 2832f44437
commit 431e96f3c5
Signed by: a-savchuk
GPG key ID: 70C0A7FF6F9C4639

View file

@ -243,34 +243,47 @@ func selectNFromBucket(bkt *bbolt.Bucket, // main bucket
continue
}
var isLinkingObj bool
var ecInfo *objectcore.ECInfo
if objType == objectSDK.TypeRegular {
var o objectSDK.Object
if err := o.Unmarshal(bytes.Clone(v)); err != nil {
return nil, nil, nil, err
}
isLinkingObj = isLinkObject(&o)
ecHeader := o.ECHeader()
if ecHeader != nil {
ecInfo = &objectcore.ECInfo{
ParentID: ecHeader.Parent(),
Index: ecHeader.Index(),
Total: ecHeader.Total(),
}
}
}
var a oid.Address
a.SetContainer(cnt)
a.SetObject(obj)
to = append(to, objectcore.Info{Address: a, Type: objType, IsLinkingObject: isLinkingObj, ECInfo: ecInfo})
info, err := prepareObjectInfo(objType, a, v)
if err != nil {
return nil, nil, nil, err
}
to = append(to, info)
count++
}
return to, offset, cursor, nil
}
func prepareObjectInfo(objType objectSDK.Type, addr oid.Address, obj []byte) (objectcore.Info, error) {
if objType != objectSDK.TypeRegular {
return objectcore.Info{Address: addr, Type: objType, IsLinkingObject: false, ECInfo: nil}, nil
}
var o objectSDK.Object
if err := o.Unmarshal(bytes.Clone(obj)); err != nil {
return objectcore.Info{}, err
}
info := objectcore.Info{
Address: addr,
Type: objType,
IsLinkingObject: isLinkObject(&o),
}
if ecHeader := o.ECHeader(); ecHeader != nil {
info.ECInfo = &objectcore.ECInfo{
ParentID: ecHeader.Parent(),
Index: ecHeader.Index(),
Total: ecHeader.Total(),
}
}
return info, nil
}
func parseContainerIDWithPrefix(containerID *cid.ID, name []byte) ([]byte, byte) {
if len(name) < bucketKeySize {
return nil, 0