pilorama: Fix TreeDrop #805
1 changed files with 2 additions and 1 deletions
|
@ -1115,11 +1115,12 @@ func (t *boltForest) TreeDrop(ctx context.Context, cid cidSDK.ID, treeID string)
|
||||||
c := tx.Cursor()
|
c := tx.Cursor()
|
||||||
prefix := make([]byte, 32)
|
prefix := make([]byte, 32)
|
||||||
cid.Encode(prefix)
|
cid.Encode(prefix)
|
||||||
for k, _ := c.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, _ = c.Next() {
|
for k, _ := c.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, _ = c.Seek(prefix) {
|
||||||
err := tx.DeleteBucket(k)
|
err := tx.DeleteBucket(k)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
_, _ = c.First() // rewind the cursor to the root page
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue
There is no need to create an intermediate slice, I believe we can just replace
c.Next()
withc.Seek(prefix)
Agree. But it is needed to add cursor rewind: https://github.com/boltdb/bolt/issues/357#issuecomment-97851571: added it at the end of
for
bodyNow it looks too complex IMHO. If I see this code in a week, I will be confused. @fyrchik , what's wrong with slice?
Nothing wrong, it bugs me when I see 2 iterations instead of 1.
In this case
buckets
slice will generally be of size 1-2, may be nothing bad.