@cryptotaxi247 / kubo / commits / 1a48e6a91

Dead code cleanup: remove Range support from blockstore

Nothing uses it, and offset+limit is a bad query mechanism for mutating data.

Tommi Virtanen committed Mar 11, 2015 at 17:24 UTC 1a48e6a91f26b3718560ff223082672200b1cb7d
3 files changed +10 -48
blocks/blockstore/blockstore.go
+8 -21
@@ -33,9 +33,6 @@ type Blockstore interface {
33
34 AllKeys(ctx context.Context) ([]u.Key, error)
35 AllKeysChan(ctx context.Context) (<-chan u.Key, error)
36 -
37 - AllKeysRange(ctx context.Context, offset int, limit int) ([]u.Key, error)
38 - AllKeysRangeChan(ctx context.Context, offset int, limit int) (<-chan u.Key, error)
36 }
37
38 func NewBlockstore(d ds.ThreadSafeDatastore) Blockstore {
@@ -85,22 +82,13 @@ func (s *blockstore) DeleteBlock(k u.Key) error {
82 return s.datastore.Delete(k.DsKey())
83 }
84
88 -func (bs *blockstore) AllKeys(ctx context.Context) ([]u.Key, error) {
89 - return bs.AllKeysRange(ctx, 0, 0)
90 -}
91 -
92 -func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
93 - return bs.AllKeysRangeChan(ctx, 0, 0)
94 -}
95 -
96 -// AllKeysRange runs a query for keys from the blockstore.
85 +// AllKeys runs a query for keys from the blockstore.
86 // this is very simplistic, in the future, take dsq.Query as a param?
98 -// if offset and limit are 0, they are ignored.
87 //
100 -// AllKeysRange respects context
101 -func (bs *blockstore) AllKeysRange(ctx context.Context, offset int, limit int) ([]u.Key, error) {
88 +// AllKeys respects context
89 +func (bs *blockstore) AllKeys(ctx context.Context) ([]u.Key, error) {
90
103 - ch, err := bs.AllKeysRangeChan(ctx, offset, limit)
91 + ch, err := bs.AllKeysChan(ctx)
92 if err != nil {
93 return nil, err
94 }
@@ -112,15 +100,14 @@ func (bs *blockstore) AllKeysRange(ctx context.Context, offset int, limit int) (
100 return keys, nil
101 }
102
115 -// AllKeysRangeChan runs a query for keys from the blockstore.
103 +// AllKeysChan runs a query for keys from the blockstore.
104 // this is very simplistic, in the future, take dsq.Query as a param?
117 -// if offset and limit are 0, they are ignored.
105 //
119 -// AllKeysRangeChan respects context
120 -func (bs *blockstore) AllKeysRangeChan(ctx context.Context, offset int, limit int) (<-chan u.Key, error) {
106 +// AllKeysChan respects context
107 +func (bs *blockstore) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
108
109 // KeysOnly, because that would be _a lot_ of data.
123 - q := dsq.Query{KeysOnly: true, Offset: offset, Limit: limit}
110 + q := dsq.Query{KeysOnly: true}
111 res, err := bs.datastore.Query(q)
112 if err != nil {
113 return nil, err
blocks/blockstore/blockstore_test.go
-17
@@ -78,23 +78,6 @@ func TestAllKeysSimple(t *testing.T) {
78 expectMatches(t, keys, keys2)
79 }
80
81 -func TestAllKeysOffsetAndLimit(t *testing.T) {
82 - N := 30
83 - bs, _ := newBlockStoreWithKeys(t, nil, N)
84 -
85 - ctx := context.Background()
86 - keys3, err := bs.AllKeysRange(ctx, N/3, N/3)
87 - if err != nil {
88 - t.Fatal(err)
89 - }
90 - for _, k3 := range keys3 {
91 - t.Log("found ", k3.Pretty())
92 - }
93 - if len(keys3) != N/3 {
94 - t.Errorf("keys3 should be: %d != %d", N/3, len(keys3))
95 - }
96 -}
97 -
81 func TestAllKeysRespectsContext(t *testing.T) {
82 N := 100
83
blocks/blockstore/write_cache.go
+2 -10
@@ -46,17 +46,9 @@ func (w *writecache) Put(b *blocks.Block) error {
46 }
47
48 func (w *writecache) AllKeys(ctx context.Context) ([]u.Key, error) {
49 - return w.blockstore.AllKeysRange(ctx, 0, 0)
49 + return w.blockstore.AllKeys(ctx)
50 }
51
52 func (w *writecache) AllKeysChan(ctx context.Context) (<-chan u.Key, error) {
53 - return w.blockstore.AllKeysRangeChan(ctx, 0, 0)
54 -}
55 -
56 -func (w *writecache) AllKeysRange(ctx context.Context, offset int, limit int) ([]u.Key, error) {
57 - return w.blockstore.AllKeysRange(ctx, offset, limit)
58 -}
59 -
60 -func (w *writecache) AllKeysRangeChan(ctx context.Context, offset int, limit int) (<-chan u.Key, error) {
61 - return w.blockstore.AllKeysRangeChan(ctx, offset, limit)
53 + return w.blockstore.AllKeysChan(ctx)
54 }