优化 文件扫描性能
This commit is contained in:
parent
819297118c
commit
86cf40564b
24
fileboy.go
24
fileboy.go
@ -113,6 +113,11 @@ func eventDispatcher(event fsnotify.Event) {
|
|||||||
func addWatcher() {
|
func addWatcher() {
|
||||||
logInfo("collecting directory information...")
|
logInfo("collecting directory information...")
|
||||||
dirsMap := map[string]bool{}
|
dirsMap := map[string]bool{}
|
||||||
|
for _, dir := range cfg.Monitor.ExceptDirs {
|
||||||
|
if dir == "." {
|
||||||
|
logAndExit("exceptDirs must is not project root path ! err path:", dir)
|
||||||
|
}
|
||||||
|
}
|
||||||
for _, dir := range cfg.Monitor.IncludeDirs {
|
for _, dir := range cfg.Monitor.IncludeDirs {
|
||||||
darr := dirParse2Array(dir)
|
darr := dirParse2Array(dir)
|
||||||
if len(darr) < 1 || len(darr) > 2 {
|
if len(darr) < 1 || len(darr) > 2 {
|
||||||
@ -147,16 +152,7 @@ func addWatcher() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
for _, dir := range cfg.Monitor.ExceptDirs {
|
|
||||||
if dir == "." {
|
|
||||||
logAndExit("exceptDirs must is not project root path ! err path:", dir)
|
|
||||||
}
|
|
||||||
p := projectFolder + "/" + dir
|
|
||||||
delete(dirsMap, p)
|
|
||||||
listFile(p, func(d string) {
|
|
||||||
delete(dirsMap, d)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
for dir := range dirsMap {
|
for dir := range dirsMap {
|
||||||
logInfo("watcher add -> ", dir)
|
logInfo("watcher add -> ", dir)
|
||||||
err := watcher.Add(dir)
|
err := watcher.Add(dir)
|
||||||
@ -224,13 +220,7 @@ func watchChangeHandler(event fsnotify.Event) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// check exceptDirs
|
// check exceptDirs
|
||||||
has := false
|
if hitDirs(event.Name, &cfg.Monitor.ExceptDirs) {
|
||||||
for _, v := range cfg.Monitor.ExceptDirs {
|
|
||||||
if strings.HasPrefix(event.Name, projectFolder+"/"+v) {
|
|
||||||
has = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if has {
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
13
util.go
13
util.go
@ -53,11 +53,24 @@ func dirParse2Array(s string) []string {
|
|||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func hitDirs(d string, dirs *[]string) bool {
|
||||||
|
d += "/"
|
||||||
|
for _, v := range *dirs {
|
||||||
|
if strings.HasPrefix(d, projectFolder+"/"+v+"/") {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
func listFile(folder string, fun func(string)) {
|
func listFile(folder string, fun func(string)) {
|
||||||
files, _ := ioutil.ReadDir(folder)
|
files, _ := ioutil.ReadDir(folder)
|
||||||
for _, file := range files {
|
for _, file := range files {
|
||||||
if file.IsDir() {
|
if file.IsDir() {
|
||||||
d := folder + "/" + file.Name()
|
d := folder + "/" + file.Name()
|
||||||
|
if hitDirs(d, &cfg.Monitor.ExceptDirs) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
fun(d)
|
fun(d)
|
||||||
listFile(d, fun)
|
listFile(d, fun)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user