Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve filesystem scanning with parallelism #189

Open
baruchiro opened this issue Sep 28, 2023 · 1 comment
Open

Improve filesystem scanning with parallelism #189

baruchiro opened this issue Sep 28, 2023 · 1 comment
Labels
enhancement New feature or request

Comments

@baruchiro
Copy link
Contributor

To scan with the filesystem plugin, we first walk over the whole directory tree, collect all the file names, and then loop over them.

err := filepath.Walk(p.Path, func(path string, fInfo os.FileInfo, err error) error {
if err != nil {
log.Fatal().Err(err).Msg("error while walking through the directory")
}
for _, ignoredFolder := range ignoredFolders {
if fInfo.Name() == ignoredFolder && fInfo.IsDir() {
return filepath.SkipDir
}
}
for _, ignoredPattern := range p.Ignored {
matched, err := filepath.Match(ignoredPattern, filepath.Base(path))
if err != nil {
return err
}
if matched && fInfo.IsDir() {
return filepath.SkipDir
}
if matched {
return nil
}
}
if fInfo.Size() == 0 {
return nil
}
if !fInfo.IsDir() {
fileList = append(fileList, path)
}
return err
})

Instead, we can immediately handle every file we find, by sending it into a channel or launching a new gorutine.

(I'm not sure what will be the best approach. I think maybe launching a new routine for each file will be the most parallelism degree, but maybe to control all the routines and wait for them, we need to use a channel from the walk function to one goroutine that will trigger all the goroutines per file)

@baruchiro baruchiro added the enhancement New feature or request label Sep 28, 2023
baruchiro pushed a commit to nirmo/2ms that referenced this issue Sep 28, 2023
@binyamin2
Copy link
Contributor

Hi, please assign for me the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants