Commit eb50103b authored by Tommi Virtanen's avatar Tommi Virtanen

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
parent ed982777
......@@ -64,10 +64,11 @@ func (bs *blockstore) Get(k u.Key) (*blocks.Block, error) {
}
func (bs *blockstore) Put(block *blocks.Block) error {
// Has is cheaper than
k := block.Key().DsKey()
// Has is cheaper than Put, so see if we already have it
exists, err := bs.datastore.Has(k)
if err != nil && exists {
if err == nil && exists {
return nil // already stored.
}
return bs.datastore.Put(k, block.Data)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment