🎨 清理块树中重复冗余的数据

This commit is contained in:
Liang Ding 2023-02-01 15:13:41 +08:00
parent 891541ad1b
commit de79543300
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
2 changed files with 3 additions and 15 deletions

View file

@ -106,6 +106,7 @@ func autoFixIndex() {
size := len(paths)
// 清理块树中重复冗余的数据
redundantPaths := treenode.GetRedundantPaths(box.ID, paths)
for _, p := range redundantPaths {
treenode.RemoveBlockTreesByPath(box.ID, p)

View file

@ -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) {