[api] Load sources into the default system store so they are permenantly cached
This commit is contained in:
parent
e243b0befe
commit
a2464d244b
1 changed files with 45 additions and 12 deletions
|
@ -292,8 +292,7 @@ Provider.prototype.merge = function () {
|
|||
//
|
||||
Provider.prototype.load = function (callback) {
|
||||
var self = this,
|
||||
stores = this._stores.map(function (name) { return self[name] })
|
||||
.concat(this.sources);
|
||||
stores = this._stores.map(function (name) { return self[name] });
|
||||
|
||||
function loadStoreSync(store) {
|
||||
if (!store.loadSync) {
|
||||
|
@ -313,18 +312,52 @@ Provider.prototype.load = function (callback) {
|
|||
: store.load(next);
|
||||
}
|
||||
|
||||
//
|
||||
// If we don't have a callback and the current
|
||||
// store is capable of loading synchronously
|
||||
// then do so.
|
||||
//
|
||||
if (!callback) {
|
||||
return common.merge(stores.map(loadStoreSync));
|
||||
function loadBatch (targets, done) {
|
||||
if (!done) {
|
||||
return common.merge(targets.map(loadStoreSync));
|
||||
}
|
||||
|
||||
async.map(targets, loadStore, function (err, objs) {
|
||||
return err ? done(err) : done(null, common.merge(objs));
|
||||
});
|
||||
}
|
||||
|
||||
async.map(stores, loadStore, function (err, objs) {
|
||||
return err ? callback(err) : callback(null, common.merge(objs));
|
||||
});
|
||||
function mergeSources (data) {
|
||||
//
|
||||
// If `data` was returned then merge it into
|
||||
// the system store.
|
||||
//
|
||||
if (data && typeof data === 'object') {
|
||||
Object.keys(data).forEach(function (key) {
|
||||
self.system.merge(key, data[key]);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function loadSources () {
|
||||
//
|
||||
// If we don't have a callback and the current
|
||||
// store is capable of loading synchronously
|
||||
// then do so.
|
||||
//
|
||||
if (!callback) {
|
||||
mergeSources(loadBatch(self.sources));
|
||||
return loadBatch(stores);
|
||||
}
|
||||
|
||||
loadBatch(self.sources, function (err, data) {
|
||||
if (err) {
|
||||
return callback(err);
|
||||
}
|
||||
|
||||
mergeSources(data);
|
||||
return loadBatch(stores, callback);
|
||||
});
|
||||
}
|
||||
|
||||
return self.sources.length
|
||||
? loadSources()
|
||||
: loadBatch(stores, callback);
|
||||
};
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue