mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-24 14:08:13 +08:00
Dead code cleanup: remove AllKeys from blockstore
Nothing uses it.
This commit is contained in:
@ -31,7 +31,6 @@ type Blockstore interface {
|
||||
Get(u.Key) (*blocks.Block, error)
|
||||
Put(*blocks.Block) error
|
||||
|
||||
AllKeys(ctx context.Context) ([]u.Key, error)
|
||||
AllKeysChan(ctx context.Context) (<-chan u.Key, error)
|
||||
}
|
||||
|
||||
@ -82,24 +81,6 @@ func (s *blockstore) DeleteBlock(k u.Key) error {
|
||||
return s.datastore.Delete(k.DsKey())
|
||||
}
|
||||
|
||||
// AllKeys runs a query for keys from the blockstore.
|
||||
// this is very simplistic, in the future, take dsq.Query as a param?
|
||||
//
|
||||
// AllKeys respects context
|
||||
func (bs *blockstore) AllKeys(ctx context.Context) ([]u.Key, error) {
|
||||
|
||||
ch, err := bs.AllKeysChan(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var keys []u.Key
|
||||
for k := range ch {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys, nil
|
||||
}
|
||||
|
||||
// AllKeysChan runs a query for keys from the blockstore.
|
||||
// this is very simplistic, in the future, take dsq.Query as a param?
|
||||
//
|
||||
|
@ -63,14 +63,24 @@ func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []u
|
||||
return bs, keys
|
||||
}
|
||||
|
||||
func collect(ch <-chan u.Key) []u.Key {
|
||||
var keys []u.Key
|
||||
for k := range ch {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
return keys
|
||||
}
|
||||
|
||||
func TestAllKeysSimple(t *testing.T) {
|
||||
bs, keys := newBlockStoreWithKeys(t, nil, 100)
|
||||
|
||||
ctx := context.Background()
|
||||
keys2, err := bs.AllKeys(ctx)
|
||||
ch, err := bs.AllKeysChan(ctx)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
keys2 := collect(ch)
|
||||
|
||||
// for _, k2 := range keys2 {
|
||||
// t.Log("found ", k2.Pretty())
|
||||
// }
|
||||
@ -90,10 +100,11 @@ func TestAllKeysRespectsContext(t *testing.T) {
|
||||
|
||||
getKeys := func(ctx context.Context) {
|
||||
started <- struct{}{}
|
||||
_, err := bs.AllKeys(ctx) // once without cancelling
|
||||
ch, err := bs.AllKeysChan(ctx) // once without cancelling
|
||||
if err != nil {
|
||||
errors <- err
|
||||
}
|
||||
_ = collect(ch)
|
||||
done <- struct{}{}
|
||||
errors <- nil // a nil one to signal break
|
||||
}
|
||||
|
@ -45,10 +45,6 @@ func (w *writecache) Put(b *blocks.Block) error {
|
||||
return w.blockstore.Put(b)
|
||||
}
|
||||
|
||||
func (w *writecache) AllKeys(ctx context.Context) ([]u.Key, error) {
|
||||
return w.blockstore.AllKeys(ctx)
|
||||
}
|
||||
|
||||
func (w *writecache) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
|
||||
return w.blockstore.AllKeysChan(ctx)
|
||||
}
|
||||
|
Reference in New Issue
Block a user