From 1becf6878b2c7ee01d3d735ee2dd9d31a6e5ed7b Mon Sep 17 00:00:00 2001 From: Acha Bill Date: Thu, 1 Feb 2024 10:42:57 +0100 Subject: [PATCH] refactor: remove iterateAll --- pkg/storer/internal/upload/uploadstore.go | 13 ------- .../internal/upload/uploadstore_test.go | 37 +++++++++++-------- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/pkg/storer/internal/upload/uploadstore.go b/pkg/storer/internal/upload/uploadstore.go index ffc0f48343f..5c59ca6347b 100644 --- a/pkg/storer/internal/upload/uploadstore.go +++ b/pkg/storer/internal/upload/uploadstore.go @@ -820,19 +820,6 @@ func DeleteTag(st storage.Store, tagID uint64) error { return nil } -func IterateAll(st storage.Store, iterateFn func(addr swarm.Address, isSynced bool) (bool, error)) error { - return st.Iterate( - storage.Query{ - Factory: func() storage.Item { return new(uploadItem) }, - }, - func(r storage.Result) (bool, error) { - address := swarm.NewAddress([]byte(r.ID[:32])) - synced := r.Entry.(*uploadItem).Synced != 0 - return iterateFn(address, synced) - }, - ) -} - func IterateAllTagItems(st storage.Store, cb func(ti *TagItem) (bool, error)) error { return st.Iterate( storage.Query{ diff --git a/pkg/storer/internal/upload/uploadstore_test.go b/pkg/storer/internal/upload/uploadstore_test.go index d8ed867ffbb..a2f7f931913 100644 --- a/pkg/storer/internal/upload/uploadstore_test.go +++ b/pkg/storer/internal/upload/uploadstore_test.go @@ -526,20 +526,27 @@ func TestChunkPutter(t *testing.T) { t.Run("iterate all", func(t *testing.T) { count := 0 - err := upload.IterateAll(ts.IndexStore(), func(addr swarm.Address, synced bool) (bool, error) { - count++ - if synced { - t.Fatal("expected synced to be false") - } - has, err := ts.ChunkStore().Has(context.Background(), addr) - if err != nil { - t.Fatalf("unexpected error in Has(...): %v", err) - } - if !has { - t.Fatalf("expected chunk to be present %s", addr.String()) - } - return false, nil - }) + err := ts.IndexStore().Iterate( + storage.Query{ + Factory: func() storage.Item { return new(upload.UploadItem) }, + }, + func(r storage.Result) (bool, error) { + address := swarm.NewAddress([]byte(r.ID[:32])) + synced := r.Entry.(*upload.UploadItem).Synced != 0 + count++ + if synced { + t.Fatal("expected synced to be false") + } + has, err := ts.ChunkStore().Has(context.Background(), address) + if err != nil { + t.Fatalf("unexpected error in Has(...): %v", err) + } + if !has { + t.Fatalf("expected chunk to be present %s", address.String()) + } + return false, nil + }, + ) if err != nil { t.Fatalf("IterateAll(...): unexpected error %v", err) } @@ -587,7 +594,7 @@ func TestChunkPutter(t *testing.T) { t.Fatalf("unexpected tagItemsCount: want 1 have %d", tagItemsCount) } if uploaded != 20 { - t.Fatalf("unexpected uploaded: want 10 have %d", uploaded) + t.Fatalf("unexpected uploaded: want 20 have %d", uploaded) } if synced != 0 { t.Fatalf("unexpected synced: want 0 have %d", synced)