Cache generated regex for each path (#891)

This commit is contained in:
JoeSmithStarkers
2020-10-26 15:57:58 +11:00
committed by GitHub
parent b3906f4b97
commit 47468fe122
2 changed files with 14 additions and 9 deletions

View File

@@ -38,15 +38,20 @@ func excludeFiles(files []string, patterns []string) ([]string, int) {
}
}
func matchFile(file string, patterns []string) bool {
if patterns != nil {
fileRegexps := generateRegexps(patterns)
func matchFileRegex(file string, fileRegexps []*regexp.Regexp) bool {
for _, regPattern := range fileRegexps {
if regPattern.MatchString(strings.ToLower(file)) {
return true
}
}
return false
}
func matchFile(file string, patterns []string) bool {
if patterns != nil {
fileRegexps := generateRegexps(patterns)
return matchFileRegex(file, fileRegexps)
}
return false

View File

@@ -651,8 +651,8 @@ func walkFilesToScan(s *models.StashConfig, f filepath.WalkFunc) error {
vidExt := config.GetVideoExtensions()
imgExt := config.GetImageExtensions()
gExt := config.GetGalleryExtensions()
excludeVid := config.GetExcludes()
excludeImg := config.GetImageExcludes()
excludeVidRegex := generateRegexps(config.GetExcludes())
excludeImgRegex := generateRegexps(config.GetImageExcludes())
return utils.SymWalk(s.Path, func(path string, info os.FileInfo, err error) error {
if err != nil {
@@ -664,12 +664,12 @@ func walkFilesToScan(s *models.StashConfig, f filepath.WalkFunc) error {
return nil
}
if !s.ExcludeVideo && matchExtension(path, vidExt) && !matchFile(path, excludeVid) {
if !s.ExcludeVideo && matchExtension(path, vidExt) && !matchFileRegex(path, excludeVidRegex) {
return f(path, info, err)
}
if !s.ExcludeImage {
if (matchExtension(path, imgExt) || matchExtension(path, gExt)) && !matchFile(path, excludeImg) {
if (matchExtension(path, imgExt) || matchExtension(path, gExt)) && !matchFileRegex(path, excludeImgRegex) {
return f(path, info, err)
}
}