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

This commit is contained in:
Liang Ding 2023-02-01 15:22:09 +08:00
parent de79543300
commit c0240f20d6
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
4 changed files with 127 additions and 92 deletions

View file

@ -55,22 +55,6 @@ type BlockTree struct {
Type string // 类型
}
func GetRootUpdated() (ret map[string]string) {
ret = map[string]string{}
blockTrees.Range(func(key, value interface{}) bool {
slice := value.(*btSlice)
slice.m.Lock()
for _, b := range slice.data {
if b.RootID == b.ID {
ret[b.RootID] = b.Updated
}
}
slice.m.Unlock()
return true
})
return
}
func GetBlockTreeByPath(path string) (ret *BlockTree) {
blockTrees.Range(func(key, value interface{}) bool {
slice := value.(*btSlice)
@ -113,62 +97,6 @@ func CountBlocks() (ret int) {
return
}
func GetRedundantPaths(boxID string, paths []string) (ret []string) {
pathsMap := map[string]bool{}
for _, path := range paths {
pathsMap[path] = true
}
btPathsMap := map[string]bool{}
blockTrees.Range(func(key, value interface{}) bool {
slice := value.(*btSlice)
slice.m.Lock()
for _, b := range slice.data {
if b.BoxID == boxID {
btPathsMap[b.Path] = true
}
}
slice.m.Unlock()
return true
})
for p, _ := range btPathsMap {
if !pathsMap[p] {
ret = append(ret, p)
}
}
ret = gulu.Str.RemoveDuplicatedElem(ret)
return
}
func GetNotExistPaths(boxID string, paths []string) (ret []string) {
pathsMap := map[string]bool{}
for _, path := range paths {
pathsMap[path] = true
}
btPathsMap := map[string]bool{}
blockTrees.Range(func(key, value interface{}) bool {
slice := value.(*btSlice)
slice.m.Lock()
for _, b := range slice.data {
if b.BoxID == boxID {
btPathsMap[b.Path] = true
}
}
slice.m.Unlock()
return true
})
for p, _ := range pathsMap {
if !btPathsMap[p] {
ret = append(ret, p)
}
}
ret = gulu.Str.RemoveDuplicatedElem(ret)
return
}
func GetBlockTreeRootByPath(boxID, path string) (ret *BlockTree) {
blockTrees.Range(func(key, value interface{}) bool {
slice := value.(*btSlice)
@ -269,21 +197,6 @@ func RemoveBlockTreesByRootID(rootID string) {
}
}
func RemoveBlockTreesByPath(boxID, path 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 {
delete(slice.data, b.ID)
slice.changed = time.Now()
}
}
slice.m.Unlock()
return true
})
}
func RemoveBlockTreesByPathPrefix(pathPrefix string) {
var ids []string
blockTrees.Range(func(key, value interface{}) bool {