From 72da0988760f78450406f1449d915ca04c57c91b Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Mon, 17 Jan 2022 12:36:56 +0300 Subject: [PATCH] [#215] container: remove old estimations without intermediate array Signed-off-by: Evgenii Stratonikov --- container/container_contract.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/container/container_contract.go b/container/container_contract.go index f00bbc9..e86d11f 100644 --- a/container/container_contract.go +++ b/container/container_contract.go @@ -577,10 +577,7 @@ func NewEpoch(epochNum int) { common.CheckAlphabetWitness(multiaddr) } - candidates := keysToDelete(ctx, epochNum) - for _, candidate := range candidates { - storage.Delete(ctx, candidate) - } + cleanupContainers(ctx, epochNum) } // StartContainerEstimation method produces StartEstimation notification. @@ -774,9 +771,7 @@ func isStorageNode(ctx storage.Context, key interop.PublicKey) bool { return false } -func keysToDelete(ctx storage.Context, epoch int) [][]byte { - results := [][]byte{} - +func cleanupContainers(ctx storage.Context, epoch int) { it := storage.Find(ctx, []byte(estimateKeyPrefix), storage.KeysOnly) for iterator.Next(it) { k := iterator.Value(it).([]byte) @@ -786,9 +781,7 @@ func keysToDelete(ctx storage.Context, epoch int) [][]byte { var n interface{} = nbytes if epoch-n.(int) > cleanupDelta { - results = append(results, k) + storage.Delete(ctx, k) } } - - return results }