Skip to content

Commit

Permalink
chore(fs): do not cache large text files
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Feb 13, 2018
1 parent fb319b2 commit 5e73031
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/util/in-memory-fs.ts
Expand Up @@ -201,11 +201,13 @@ export class InMemoryFileSystem {

const fileContent = await this.disk.readFile(filePath, 'utf-8');

const item = this.getItem(filePath);
item.exists = true;
item.isFile = true;
item.isDirectory = false;
item.fileText = fileContent;
if (fileContent.length < MAX_TEXT_CACHE) {
const item = this.getItem(filePath);
item.exists = true;
item.isFile = true;
item.isDirectory = false;
item.fileText = fileContent;
}

return fileContent;
}
Expand All @@ -223,10 +225,12 @@ export class InMemoryFileSystem {

const fileContent = this.disk.readFileSync(filePath, 'utf-8');

item.exists = true;
item.isFile = true;
item.isDirectory = false;
item.fileText = fileContent;
if (fileContent.length < MAX_TEXT_CACHE) {
item.exists = true;
item.isFile = true;
item.isDirectory = false;
item.fileText = fileContent;
}

return fileContent;
}
Expand Down Expand Up @@ -656,3 +660,10 @@ const IGNORE = [
'desktop.ini',
'thumbs.db'
];

// only cache if it's less than 5MB-ish (using .length as a rough guess)
// why 5MB? idk, seems like a good number for source text
// it's pretty darn large to cover almost ALL legitimate source files
// and anything larger is probably a REALLY large file and a rare case
// which we don't need to eat up memory for
const MAX_TEXT_CACHE = 5242880;

0 comments on commit 5e73031

Please sign in to comment.