release metadata is in official only

The point of the other catalogs is to allow local packages to override
server packages. This has nothing to do with releases. So rather than
keep release metadata in memory multiple times and force developers to
wonder "what's the different between catalog.complete.getReleaseTrack
and catalog.official.getReleaseTrack?", now it really just only exists
on catalog.official.
This commit is contained in:
David Glasser
2014-08-14 16:24:16 -07:00
parent 924195b224
commit 44bcae916d
3 changed files with 111 additions and 85 deletions

View File

@@ -29,8 +29,6 @@ baseCatalog.BaseCatalog = function () {
self.packages = null;
self.versions = null; // package name -> version -> object
self.builds = null;
self.releaseTracks = null;
self.releaseVersions = null;
// We use the initialization design pattern because it makes it easier to use
// both of our catalogs as singletons.
@@ -49,8 +47,6 @@ _.extend(baseCatalog.BaseCatalog.prototype, {
self.packages = [];
self.versions = {};
self.builds = [];
self.releaseTracks = [];
self.releaseVersions = [];
},
// Throw if the catalog's self.initialized value has not been set to true.
@@ -74,7 +70,7 @@ _.extend(baseCatalog.BaseCatalog.prototype, {
return;
_.each(
['packages', 'builds', 'releaseTracks', 'releaseVersions'],
['packages', 'builds'],
function (field) {
self[field].push.apply(self[field], collections[field]);
});
@@ -121,61 +117,6 @@ _.extend(baseCatalog.BaseCatalog.prototype, {
return false;
},
// Returns general (non-version-specific) information about a
// release track, or null if there is no such release track.
getReleaseTrack: function (name) {
var self = this;
buildmessage.assertInCapture();
self._requireInitialized();
return self._recordOrRefresh(function () {
return _.findWhere(self.releaseTracks, { name: name });
});
},
// Return information about a particular release version, or null if such
// release version does not exist.
//
// XXX: notInitialized : don't require initialization. This is not the right thing
// to do long term, but it is the easiest way to deal with versionFrom without
// serious refactoring.
getReleaseVersion: function (track, version, notInitialized) {
var self = this;
buildmessage.assertInCapture();
if (!notInitialized) self._requireInitialized();
return self._recordOrRefresh(function () {
return _.findWhere(self.releaseVersions,
{ track: track, version: version });
});
},
// Return an array with the names of all of the release tracks that we know
// about, in no particular order.
getAllReleaseTracks: function () {
var self = this;
self._requireInitialized();
return _.pluck(self.releaseTracks, 'name');
},
// Given a release track, return all recommended versions for this track, sorted
// by their orderKey. Returns the empty array if the release track does not
// exist or does not have any recommended versions.
getSortedRecommendedReleaseVersions: function (track, laterThanOrderKey) {
var self = this;
self._requireInitialized();
var recommended = _.filter(self.releaseVersions, function (v) {
if (v.track !== track || !v.recommended)
return false;
return !laterThanOrderKey || v.orderKey > laterThanOrderKey;
});
var recSort = _.sortBy(recommended, function (rec) {
return rec.orderKey;
});
recSort.reverse();
return _.pluck(recSort, "version");
},
// Return an array with the names of all of the packages that we
// know about, in no particular order.
getAllPackageNames: function () {
@@ -327,28 +268,6 @@ _.extend(baseCatalog.BaseCatalog.prototype, {
return _.where(self.builds, { versionId: versionRecord._id });
},
// Returns the default release version: the latest recommended version on the
// default track. Returns null if no such thing exists (even after syncing
// with the server, which it only does if there is no eligible release
// version).
getDefaultReleaseVersion: function (track) {
var self = this;
buildmessage.assertInCapture();
self._requireInitialized();
if (!track)
track = catalog.DEFAULT_TRACK;
var getDef = function () {
var versions = self.getSortedRecommendedReleaseVersions(track);
if (!versions.length)
return null;
return {track: track, version: versions[0]};
};
return self._recordOrRefresh(getDef);
},
// Reload catalog data to account for new information if needed.
refresh: function () {
throw new Error("no such thing as a base refresh");

View File

@@ -35,14 +35,18 @@ catalog.DEFAULT_TRACK = 'METEOR-CORE';
var OfficialCatalog = function () {
var self = this;
// We inherit from the BaseCatalog class.
BaseCatalog.call(self);
// Set this to true if we are not going to connect to the remote package
// server, and will only use the cached data.json file for our package
// information. This means that the catalog might be out of date on the latest
// developments.
self.offline = null;
// We inherit from the protolog class, since we are a catalog.
BaseCatalog.call(self);
// The official catalog is the only one with release metadata.
self.releaseTracks = null;
self.releaseVersions = null;
};
util.inherits(OfficialCatalog, BaseCatalog);
@@ -66,6 +70,32 @@ _.extend(OfficialCatalog.prototype, {
self.initialized = true;
},
reset: function () {
var self = this;
BaseCatalog.prototype.reset.call(self);
self.releaseTracks = [];
self.releaseVersions = [];
},
_insertServerPackages: function (serverPackageData) {
var self = this;
// Insert packages/versions/builds.
BaseCatalog.prototype._insertServerPackages.call(self, serverPackageData);
// Now insert release metadata.
var collections = serverPackageData.collections;
if (!collections)
return;
_.each(
['releaseTracks', 'releaseVersions'],
function (field) {
self[field].push.apply(self[field], collections[field]);
});
},
_refreshingIsProductive: function () {
return true;
},
@@ -160,6 +190,83 @@ _.extend(OfficialCatalog.prototype, {
if (allPackageData && allPackageData.collections) {
self._insertServerPackages(allPackageData);
}
},
// Returns general (non-version-specific) information about a
// release track, or null if there is no such release track.
getReleaseTrack: function (name) {
var self = this;
buildmessage.assertInCapture();
self._requireInitialized();
return self._recordOrRefresh(function () {
return _.findWhere(self.releaseTracks, { name: name });
});
},
// Return information about a particular release version, or null if such
// release version does not exist.
//
// XXX: notInitialized : don't require initialization. This is not the right thing
// to do long term, but it is the easiest way to deal with versionFrom without
// serious refactoring.
getReleaseVersion: function (track, version, notInitialized) {
var self = this;
buildmessage.assertInCapture();
if (!notInitialized) self._requireInitialized();
return self._recordOrRefresh(function () {
return _.findWhere(self.releaseVersions,
{ track: track, version: version });
});
},
// Return an array with the names of all of the release tracks that we know
// about, in no particular order.
getAllReleaseTracks: function () {
var self = this;
self._requireInitialized();
return _.pluck(self.releaseTracks, 'name');
},
// Given a release track, return all recommended versions for this track, sorted
// by their orderKey. Returns the empty array if the release track does not
// exist or does not have any recommended versions.
getSortedRecommendedReleaseVersions: function (track, laterThanOrderKey) {
var self = this;
self._requireInitialized();
var recommended = _.filter(self.releaseVersions, function (v) {
if (v.track !== track || !v.recommended)
return false;
return !laterThanOrderKey || v.orderKey > laterThanOrderKey;
});
var recSort = _.sortBy(recommended, function (rec) {
return rec.orderKey;
});
recSort.reverse();
return _.pluck(recSort, "version");
},
// Returns the default release version: the latest recommended version on the
// default track. Returns null if no such thing exists (even after syncing
// with the server, which it only does if there is no eligible release
// version).
getDefaultReleaseVersion: function (track) {
var self = this;
buildmessage.assertInCapture();
self._requireInitialized();
if (!track)
track = catalog.DEFAULT_TRACK;
var getDef = function () {
var versions = self.getSortedRecommendedReleaseVersions(track);
if (!versions.length)
return null;
return {track: track, version: versions[0]};
};
return self._recordOrRefresh(getDef);
}
});

View File

@@ -1396,7 +1396,7 @@ main.registerCommand({
}
var solutionReleaseVersion = _.find(releaseVersionsToTry, function (versionToTry) {
var releaseRecord = doOrDie(function () {
return catalog.complete.getReleaseVersion(releaseTrack, versionToTry);
return catalog.official.getReleaseVersion(releaseTrack, versionToTry);
});
if (!releaseRecord)
throw Error("missing release record?");