@cryptotaxi247 / kubo / commits / 63c25285b

Dead code cleanup: remove AllKeys from blockstore

Nothing uses it.

Tommi Virtanen committed Mar 11, 2015 at 17:29 UTC 63c25285b2d58e4458b9fdd9a8159593bcd84bcc
3 files changed +13 -25
blocks/blockstore/blockstore.go
-19
@@ -31,7 +31,6 @@ type Blockstore interface {
31 Get(u.Key) (*blocks.Block, error)
32 Put(*blocks.Block) error
33
34 - AllKeys(ctx context.Context) ([]u.Key, error)
34 AllKeysChan(ctx context.Context) (<-chan u.Key, error)
35 }
36
@@ -82,24 +81,6 @@ func (s *blockstore) DeleteBlock(k u.Key) error {
81 return s.datastore.Delete(k.DsKey())
82 }
83
85 -// AllKeys runs a query for keys from the blockstore.
86 -// this is very simplistic, in the future, take dsq.Query as a param?
87 -//
88 -// AllKeys respects context
89 -func (bs *blockstore) AllKeys(ctx context.Context) ([]u.Key, error) {
90 -
91 - ch, err := bs.AllKeysChan(ctx)
92 - if err != nil {
93 - return nil, err
94 - }
95 -
96 - var keys []u.Key
97 - for k := range ch {
98 - keys = append(keys, k)
99 - }
100 - return keys, nil
101 -}
102 -
84 // AllKeysChan runs a query for keys from the blockstore.
85 // this is very simplistic, in the future, take dsq.Query as a param?
86 //
blocks/blockstore/blockstore_test.go
+13 -2
@@ -63,14 +63,24 @@ func newBlockStoreWithKeys(t *testing.T, d ds.Datastore, N int) (Blockstore, []u
63 return bs, keys
64 }
65
66 +func collect(ch <-chan u.Key) []u.Key {
67 + var keys []u.Key
68 + for k := range ch {
69 + keys = append(keys, k)
70 + }
71 + return keys
72 +}
73 +
74 func TestAllKeysSimple(t *testing.T) {
75 bs, keys := newBlockStoreWithKeys(t, nil, 100)
76
77 ctx := context.Background()
70 - keys2, err := bs.AllKeys(ctx)
78 + ch, err := bs.AllKeysChan(ctx)
79 if err != nil {
80 t.Fatal(err)
81 }
82 + keys2 := collect(ch)
83 +
84 // for _, k2 := range keys2 {
85 // t.Log("found ", k2.Pretty())
86 // }
@@ -90,10 +100,11 @@ func TestAllKeysRespectsContext(t *testing.T) {
100
101 getKeys := func(ctx context.Context) {
102 started <- struct{}{}
93 - _, err := bs.AllKeys(ctx) // once without cancelling
103 + ch, err := bs.AllKeysChan(ctx) // once without cancelling
104 if err != nil {
105 errors <- err
106 }
107 + _ = collect(ch)
108 done <- struct{}{}
109 errors <- nil // a nil one to signal break
110 }
blocks/blockstore/write_cache.go
-4
@@ -45,10 +45,6 @@ func (w *writecache) Put(b *blocks.Block) error {
45 return w.blockstore.Put(b)
46 }
47
48 -func (w *writecache) AllKeys(ctx context.Context) ([]u.Key, error) {
49 - return w.blockstore.AllKeys(ctx)
50 -}
51 -
48 func (w *writecache) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
49 return w.blockstore.AllKeysChan(ctx)
50 }