Small performance improvement by accepting an optional package meta to avoid re-reading it.

Fix tests if previous run left dummy directories.
This commit is contained in:
André Cruz
2013-05-17 11:47:00 +01:00
parent febc3b7936
commit 7c96eb0819
9 changed files with 170 additions and 40 deletions

View File

@@ -17,7 +17,7 @@ mout.object.mixIn(GitResolver, Resolver);
// -----------------
GitResolver.prototype._hasNew = function (pkgMeta) {
GitResolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
var oldResolution = pkgMeta._resolution || {};
return this._findResolution()

View File

@@ -38,15 +38,11 @@ Resolver.prototype.getTempDir = function () {
return this._tempDir;
};
Resolver.prototype.hasNew = function (canonicalPkg) {
Resolver.prototype.hasNew = function (canonicalPkg, pkgMeta) {
var promise;
var metaFile;
var that = this;
// TODO: Change arguments to canonicalPkg, pkgMeta
// where pkgMeta is optional
// Change _hasNew to the same
// If already working, error out
if (this._working) {
return Q.reject(createError('Already working', 'EWORKING'));
@@ -54,18 +50,18 @@ Resolver.prototype.hasNew = function (canonicalPkg) {
this._working = true;
// Avoid reading the package meta if _hasNew was not rewritten
if (this._hasNew === Resolver.prototype._hasNew) {
promise = this._hasNew();
// Avoid reading the package meta if already given
if (pkgMeta) {
promise = this._hasNew(canonicalPkg, pkgMeta);
// Otherwise call _hasNew with both the package meta and the canonical package
} else {
metaFile = path.join(canonicalPkg, '.bower.json');
promise = Q.nfcall(fs.readFile, metaFile)
.then(function (contents) {
var pkgMeta = JSON.parse(contents.toString());
return that._hasNew(pkgMeta, canonicalPkg);
return that._hasNew(canonicalPkg, pkgMeta);
}, function () {
return true; // Simply resolve to true if there was an error reading the meta
return true; // Simply resolve to true if there was an error reading the file
});
}
@@ -130,7 +126,7 @@ Resolver.prototype._resolve = function () {
// -----------------
Resolver.prototype._hasNew = function (pkgMeta) {
Resolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
return Q.resolve(true);
};

View File

@@ -35,7 +35,7 @@ util.inherits(UrlResolver, Resolver);
// -----------------
UrlResolver.prototype._hasNew = function (pkgMeta) {
UrlResolver.prototype._hasNew = function (canonicalPkg, pkgMeta) {
var oldCacheHeaders = pkgMeta._cacheHeaders || {};
var reqHeaders = {};