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 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 {
|
func matchFile(file string, patterns []string) bool {
|
||||||
if patterns != nil {
|
if patterns != nil {
|
||||||
fileRegexps := generateRegexps(patterns)
|
fileRegexps := generateRegexps(patterns)
|
||||||
|
|
||||||
for _, regPattern := range fileRegexps {
|
return matchFileRegex(file, fileRegexps)
|
||||||
if regPattern.MatchString(strings.ToLower(file)) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
|||||||
@@ -651,8 +651,8 @@ func walkFilesToScan(s *models.StashConfig, f filepath.WalkFunc) error {
|
|||||||
vidExt := config.GetVideoExtensions()
|
vidExt := config.GetVideoExtensions()
|
||||||
imgExt := config.GetImageExtensions()
|
imgExt := config.GetImageExtensions()
|
||||||
gExt := config.GetGalleryExtensions()
|
gExt := config.GetGalleryExtensions()
|
||||||
excludeVid := config.GetExcludes()
|
excludeVidRegex := generateRegexps(config.GetExcludes())
|
||||||
excludeImg := config.GetImageExcludes()
|
excludeImgRegex := generateRegexps(config.GetImageExcludes())
|
||||||
|
|
||||||
return utils.SymWalk(s.Path, func(path string, info os.FileInfo, err error) error {
|
return utils.SymWalk(s.Path, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -664,12 +664,12 @@ func walkFilesToScan(s *models.StashConfig, f filepath.WalkFunc) error {
|
|||||||
return nil
|
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)
|
return f(path, info, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if !s.ExcludeImage {
|
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)
|
return f(path, info, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user