blocks: Don't re-Put blocks we already have
Commit 1192be196b3d0acca2e2dce5ffd5d12a924fdc5a tried to do this, but had a simple mistake. Functions returning `bool, error` pretty much never return `true, anError`, so that branch was never taken. Also fix the partial sentence in the
Tommi Virtanen committed
Apr 28, 2015 at 16:05 UTC
a743290316332fcdac1caa79721bace55dc9351d
1 file changed
+3
-2
blocks/blockstore/blockstore.go
+3
-2
@@ -64,10 +64,11 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
64
}
65
66
func (bs *blockstore) Put(block *blocks.Block) error {
67
- // Has is cheaper than
67
k := block.Key().DsKey()
68
+
69
+ // Has is cheaper than Put, so see if we already have it
70
exists, err := bs.datastore.Has(k)
70
- if err != nil && exists {
71
+ if err == nil && exists {
72
return nil // already stored.
73
}
74
return bs.datastore.Put(k, block.Data)