[#1262] metabase: Remove list index in place Delete

Signed-off-by: Evgenii Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
Evgenii Stratonikov 2022-03-21 18:39:46 +03:00 committed by Alex Vanin
parent 43867a3093
commit de5a2f6574

View file

@ -200,16 +200,16 @@ func delListIndexItem(tx *bbolt.Tx, item namedBucketItem) error {
} }
// remove element from the list // remove element from the list
newLst := make([][]byte, 0, len(lst))
for i := range lst { for i := range lst {
if !bytes.Equal(item.val, lst[i]) { if bytes.Equal(item.val, lst[i]) {
newLst = append(newLst, lst[i]) copy(lst[i:], lst[i+1:])
lst = lst[:len(lst)-1]
break
} }
} }
// if list empty, remove the key from <list> bucket // if list empty, remove the key from <list> bucket
if len(newLst) == 0 { if len(lst) == 0 {
_ = bkt.Delete(item.key) // ignore error, best effort there _ = bkt.Delete(item.key) // ignore error, best effort there
return nil return nil