mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-25 06:58:18 +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)
|
Get(u.Key) (*blocks.Block, error)
|
||||||
Put(*blocks.Block) error
|
Put(*blocks.Block) error
|
||||||
|
|
||||||
AllKeys(ctx context.Context) ([]u.Key, error)
|
|
||||||
AllKeysChan(ctx context.Context) (<-chan 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())
|
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.
|
// AllKeysChan runs a query for keys from the blockstore.
|
||||||
// this is very simplistic, in the future, take dsq.Query as a param?
|
// 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
|
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) {
|
func TestAllKeysSimple(t *testing.T) {
|
||||||
bs, keys := newBlockStoreWithKeys(t, nil, 100)
|
bs, keys := newBlockStoreWithKeys(t, nil, 100)
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
keys2, err := bs.AllKeys(ctx)
|
ch, err := bs.AllKeysChan(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
keys2 := collect(ch)
|
||||||
|
|
||||||
// for _, k2 := range keys2 {
|
// for _, k2 := range keys2 {
|
||||||
// t.Log("found ", k2.Pretty())
|
// t.Log("found ", k2.Pretty())
|
||||||
// }
|
// }
|
||||||
@ -90,10 +100,11 @@ func TestAllKeysRespectsContext(t *testing.T) {
|
|||||||
|
|
||||||
getKeys := func(ctx context.Context) {
|
getKeys := func(ctx context.Context) {
|
||||||
started <- struct{}{}
|
started <- struct{}{}
|
||||||
_, err := bs.AllKeys(ctx) // once without cancelling
|
ch, err := bs.AllKeysChan(ctx) // once without cancelling
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors <- err
|
errors <- err
|
||||||
}
|
}
|
||||||
|
_ = collect(ch)
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
errors <- nil // a nil one to signal break
|
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)
|
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) {
|
func (w *writecache) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
|
||||||
return w.blockstore.AllKeysChan(ctx)
|
return w.blockstore.AllKeysChan(ctx)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user