Skip to content

Commit

Permalink
Merge pull request #666 from ember-fastboot/cache-exists
Browse files Browse the repository at this point in the history
memoize existsSync calls on the fastboot instance itself
  • Loading branch information
stefanpenner authored Mar 3, 2019
2 parents d688533 + aac6fe5 commit 43ffc65
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ module.exports = {

init() {
this._super.init && this._super.init.apply(this, arguments);
this._existsCache = new Map();
},

existsSync(path) {
if (this._existsCache.has(path)) {
return this._existsCache.get(path);
}

const exists = existsSync(path);

this._existsCache.set(path, exists);
return exists;
},

/**
Expand Down Expand Up @@ -139,7 +151,7 @@ module.exports = {
const currentAddonFastbootPath = path.join(addon.root, 'fastboot');

let fastbootTree;
if (existsSync(currentAddonFastbootPath)) {
if (this.existsSync(currentAddonFastbootPath)) {
fastbootTree = this.treeGenerator(currentAddonFastbootPath);
}

Expand Down Expand Up @@ -168,7 +180,7 @@ module.exports = {

// check the parent containing the fastboot directory
const projectFastbootPath = path.join(this.project.root, 'fastboot');
if (existsSync(projectFastbootPath)) {
if (this.existsSync(projectFastbootPath)) {
let fastbootTree = this.treeGenerator(projectFastbootPath);
fastbootTrees.push(fastbootTree);
}
Expand Down

0 comments on commit 43ffc65

Please sign in to comment.