Open frantic1048 opened 4 years ago
update: fixed test where callback is invoked multiple times on some case
Hi there, Thanks for the contribution. I like the idea of speeding it up in general through parallelization but this isn't currently passing the tests. It looks like it's not properly failing if the folder case is wrong, at least that's the test failing on my machine.
Please make sure the tests pass locally and update.
@Urthen Thanks for the inform. I revised the issue today and made a whole new fix. Of course, failing tests are fixed.
I updated the summary of changes in PR description, and added descriptions of key changes/questions in inline discussions.
Also, I resolved all outdated inline discussions opened by myself.
Review commits one by one is recommended since there is an ESlint styling fix commit.
This fixes issue #52.
Changes
Introduce async mutex to prevent calling fs.readdir() multiple times on the same path
This is the major content of this PR.
pathCache
now becomes direct cache offs.readdir()
, regardless of being "good" or not. It just holds the result offs.readdir()
.There is a new Map
visitedPathMutexRecord
along withpathCache
. It holds a mutex for each path we will visit, to achieve the following behavior.Before the cache for a directory(let's say
tippy
here) is ready, we do the following process exclusively(non-parallelized):tippy
is ready and use the existing cache.fs.readdir()
withtippy
fs.readdir()
to cache. Cache fortippy
is now ready.After the cache of
tippy
is ready, there is only step 1, and it is being processed parallelized. on further calls togetFilenamesInDir()
with directorytippy
.Apply
lintfix
in projectThis is a separate commit at the first of all commits.
I found ESLint is warning during resolving the issue. And there are an existing ESLint config and a
lintfix
script inpackage.json
I think it is fair to apply it to prevent further distraction.
BTW, how about putting lint in CI jobs to keep things consistent?