From 167c52a1a977301f9899d9b617aaa34545c7bd73 Mon Sep 17 00:00:00 2001 From: Anton Nikiforov Date: Tue, 23 Apr 2024 15:21:29 +0300 Subject: [PATCH] [#1103] node: Reduce amount of lines for method `StorageEngine.head` Signed-off-by: Anton Nikiforov --- pkg/local_object_storage/engine/head.go | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/pkg/local_object_storage/engine/head.go b/pkg/local_object_storage/engine/head.go index ba5e7cc1d..f56e1b772 100644 --- a/pkg/local_object_storage/engine/head.go +++ b/pkg/local_object_storage/engine/head.go @@ -67,20 +67,17 @@ func (e *StorageEngine) Head(ctx context.Context, prm HeadPrm) (res HeadRes, err func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) { ctx, span := tracing.StartSpanFromContext(ctx, "StorageEngine.head") defer span.End() - if e.metrics != nil { defer elapsed("Head", e.metrics.AddMethodDuration)() } var ( - head *objectSDK.Object - siErr *objectSDK.SplitInfoError - outSI *objectSDK.SplitInfo - + head *objectSDK.Object + siErr *objectSDK.SplitInfoError + outSI *objectSDK.SplitInfo outError error = new(apistatus.ObjectNotFound) + shPrm shard.HeadPrm ) - - var shPrm shard.HeadPrm shPrm.SetAddress(prm.addr) shPrm.SetRaw(prm.raw) @@ -94,44 +91,34 @@ func (e *StorageEngine) head(ctx context.Context, prm HeadPrm) (HeadRes, error) if outSI == nil { outSI = objectSDK.NewSplitInfo() } - util.MergeSplitInfo(siErr.SplitInfo(), outSI) - _, withLink := outSI.Link() _, withLast := outSI.LastPart() - // stop iterating over shards if SplitInfo structure is complete if withLink && withLast { return true } - return false case client.IsErrObjectAlreadyRemoved(err): outError = err - return true // stop, return it back case shard.IsErrObjectExpired(err): // object is found but should not // be returned outError = new(apistatus.ObjectNotFound) - return true default: e.reportShardError(sh, "could not head object from shard", err) return false } } - head = res.Object() - return true }) if outSI != nil { return HeadRes{}, logicerr.Wrap(objectSDK.NewSplitInfoError(outSI)) - } - - if head == nil { + } else if head == nil { return HeadRes{}, outError }