[#611] Process delimiters on the object info cache hit

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2022-06-24 15:39:30 +03:00 committed by Alex Vanin
parent aee7450880
commit 97f81d3270

View file

@ -672,7 +672,25 @@ func triageExtendedObjects(allObjects []*data.ExtendedObjectInfo) (prefixes []st
func (n *layer) objectInfoFromObjectsCacheOrNeoFS(ctx context.Context, bktInfo *data.BucketInfo, obj oid.ID, prefix, delimiter string) *data.ObjectInfo { func (n *layer) objectInfoFromObjectsCacheOrNeoFS(ctx context.Context, bktInfo *data.BucketInfo, obj oid.ID, prefix, delimiter string) *data.ObjectInfo {
if objInfo := n.objCache.GetObject(newAddress(bktInfo.CID, obj)); objInfo != nil { if objInfo := n.objCache.GetObject(newAddress(bktInfo.CID, obj)); objInfo != nil {
return objInfo // that's the simplest solution
// consider doing something else
if !strings.HasPrefix(objInfo.Name, prefix) {
return nil
}
if len(delimiter) == 0 {
return objInfo
}
copiedObjInfo := *objInfo
tail := strings.TrimPrefix(copiedObjInfo.Name, prefix)
index := strings.Index(tail, delimiter)
if index >= 0 {
copiedObjInfo.IsDir = true
copiedObjInfo.Size = 0
copiedObjInfo.Headers = nil
copiedObjInfo.ContentType = ""
copiedObjInfo.Name = prefix + tail[:index+1]
}
return &copiedObjInfo
} }
meta, err := n.objectHead(ctx, bktInfo, obj) meta, err := n.objectHead(ctx, bktInfo, obj)