♻️ Use ezcache to only remember files for five minutes
This commit is contained in:
parent
ac0baba3a8
commit
8d74dc24e5
3 changed files with 22 additions and 21 deletions
|
|
@ -10,7 +10,9 @@ import (
|
|||
fp "path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"codeberg.org/danjones000/ezcache"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
|
|
@ -82,24 +84,6 @@ func processFile(input processInput) (processed bool, processError, cbError erro
|
|||
return
|
||||
}
|
||||
|
||||
type fileMap map[string][]os.DirEntry
|
||||
|
||||
func (fm fileMap) GetFiles(path string) []os.DirEntry {
|
||||
files, ok := fm[path]
|
||||
if ok {
|
||||
return files
|
||||
}
|
||||
fm.ReadPath(path)
|
||||
return fm[path]
|
||||
}
|
||||
|
||||
func (fm fileMap) ReadPath(path string) {
|
||||
if _, ok := fm[path]; ok {
|
||||
return
|
||||
}
|
||||
fm[path], _ = os.ReadDir(path)
|
||||
}
|
||||
|
||||
func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err error) {
|
||||
err = ensureExtRe(d.Config)
|
||||
if err != nil {
|
||||
|
|
@ -109,8 +93,13 @@ func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err e
|
|||
cb = DryRun(os.Stdout)
|
||||
}
|
||||
count := 0
|
||||
allFiles := fileMap{}
|
||||
allFiles, cacheErr := ezcache.New(os.ReadDir, 5*time.Minute)
|
||||
if cacheErr != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var files []os.DirEntry
|
||||
var filesErr error
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
|
|
@ -121,7 +110,10 @@ func WalkFiles(d *Data, stopOnError bool, gp GroupPrinter, cb ShowWalker) (err e
|
|||
}
|
||||
showstart:
|
||||
for _, source := range s.Sources {
|
||||
files = allFiles.GetFiles(source)
|
||||
files, filesErr = allFiles.Get(source)
|
||||
if filesErr != nil {
|
||||
return filesErr
|
||||
}
|
||||
for _, file := range files {
|
||||
pIn := processInput{file, source, s, d.Config.extRe, d.Config.Skip, cb}
|
||||
processed, processErr, cbErr := processFile(pIn)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue