From f620f2f047aa4f3775a87c0f6235437343499234 Mon Sep 17 00:00:00 2001 From: Ben Newman Date: Tue, 12 Jul 2016 13:32:09 -0400 Subject: [PATCH] Save .meteor/local/resolver-result-cache.json to improve startup performance. --- tools/project-context.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/tools/project-context.js b/tools/project-context.js index 896b93751c..7daf27666f 100644 --- a/tools/project-context.js +++ b/tools/project-context.js @@ -210,7 +210,7 @@ _.extend(ProjectContext.prototype, { // calls to the constraint solver, the constraint solver can be // more efficient by caching or memoizing its work. We choose not // to reset this when reset() is called more than once. - self._resolverResultCache = (self._resolverResultCache || {}); + self._readResolverResultCache(); }, readProjectMetadata: function () { @@ -559,11 +559,40 @@ _.extend(ProjectContext.prototype, { anticipatedPrereleases: anticipatedPrereleases }); + self._saveResolverResultCache(); + self._completedStage = STAGE.RESOLVE_CONSTRAINTS; }); }); }), + _readResolverResultCache() { + if (! this._resolverResultCache) { + try { + this._resolverResultCache = + JSON.parse(files.readFile(files.pathJoin( + this.projectLocalDir, + "resolver-result-cache.json" + ))); + } catch (e) { + if (e.code !== "ENOENT") throw e; + this._resolverResultCache = {}; + } + } + + return this._resolverResultCache; + }, + + _saveResolverResultCache() { + files.writeFileAtomically( + files.pathJoin( + this.projectLocalDir, + "resolver-result-cache.json" + ), + JSON.stringify(this._resolverResultCache) + "\n" + ); + }, + // When running test-packages for an app with local packages, this // method will return the original app dir, as opposed to the temporary // testRunnerAppDir created for the tests.