Skip to content

Commit

Permalink
refactor: remove iterateAll
Browse files Browse the repository at this point in the history
  • Loading branch information
acha-bill committed Feb 1, 2024
1 parent 9c1a8d3 commit 1becf68
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
13 changes: 0 additions & 13 deletions pkg/storer/internal/upload/uploadstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
37 changes: 22 additions & 15 deletions pkg/storer/internal/upload/uploadstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 1becf68

Please sign in to comment.