mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 12:54:38 +03:00
Cache generated regex for each path (#891)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user