🎨 清理块树中重复冗余的数据
This commit is contained in:
parent
891541ad1b
commit
de79543300
2 changed files with 3 additions and 15 deletions
|
@ -106,6 +106,7 @@ func autoFixIndex() {
|
|||
|
||||
size := len(paths)
|
||||
|
||||
// 清理块树中重复冗余的数据
|
||||
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
|
||||
for _, p := range redundantPaths {
|
||||
treenode.RemoveBlockTreesByPath(box.ID, p)
|
||||
|
|
|
@ -270,31 +270,18 @@ func RemoveBlockTreesByRootID(rootID string) {
|
|||
}
|
||||
|
||||
func RemoveBlockTreesByPath(boxID, path string) {
|
||||
var ids []string
|
||||
blockTrees.Range(func(key, value interface{}) bool {
|
||||
slice := value.(*btSlice)
|
||||
slice.m.Lock()
|
||||
for _, b := range slice.data {
|
||||
if b.Path == path && b.BoxID == boxID {
|
||||
ids = append(ids, b.RootID)
|
||||
delete(slice.data, b.ID)
|
||||
slice.changed = time.Now()
|
||||
}
|
||||
}
|
||||
slice.m.Unlock()
|
||||
return true
|
||||
})
|
||||
|
||||
ids = gulu.Str.RemoveDuplicatedElem(ids)
|
||||
for _, id := range ids {
|
||||
val, ok := blockTrees.Load(btHash(id))
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
slice := val.(*btSlice)
|
||||
slice.m.Lock()
|
||||
delete(slice.data, id)
|
||||
slice.m.Unlock()
|
||||
slice.changed = time.Now()
|
||||
}
|
||||
}
|
||||
|
||||
func RemoveBlockTreesByPathPrefix(pathPrefix string) {
|
||||
|
|
Loading…
Add table
Reference in a new issue