Skip to content

Commit

Permalink
Ensure no more than MAX_FILES are read when collecting workspace stats,
Browse files Browse the repository at this point in the history
  • Loading branch information
Rachel Macfarlane committed Aug 22, 2019
1 parent 0ec80b4 commit bdffaf3
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/vs/platform/diagnostics/node/diagnosticsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,26 @@ export function collectWorkspaceStats(folder: string, filter: string[]): Promise
return done(results);
}

if (token.count > MAX_FILES) {
token.maxReached = true;
return done(results);
}

let pending = files.length;
if (pending === 0) {
return done(results);
}

for (const file of files) {
if (token.maxReached) {
return done(results);
}
let filesToRead = files;
if (token.count + files.length > MAX_FILES) {
token.maxReached = true;
pending = MAX_FILES - token.count;
filesToRead = files.slice(0, pending);
}

token.count += files.length;

for (const file of filesToRead) {
stat(join(dir, file), (err, stats) => {
// Ignore files that can't be read
if (err) {
Expand All @@ -108,11 +118,6 @@ export function collectWorkspaceStats(folder: string, filter: string[]): Promise
}
}
} else {
if (token.count >= MAX_FILES) {
token.maxReached = true;
}

token.count++;
results.push(file);

if (--pending === 0) {
Expand Down

0 comments on commit bdffaf3

Please sign in to comment.