mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Refactored Resources._fetch
to async-await
- aids with readability
This commit is contained in:
parent
df76883378
commit
b0cf15cb94
1 changed files with 12 additions and 12 deletions
|
@ -116,7 +116,7 @@ class Resources {
|
||||||
* @returns {Promise}
|
* @returns {Promise}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
_fetch(resourceConfig, options = {offset: 0, limit: 999}) {
|
async _fetch(resourceConfig, options = {offset: 0, limit: 999}) {
|
||||||
debug('_fetch', resourceConfig.type, resourceConfig.modelOptions);
|
debug('_fetch', resourceConfig.type, resourceConfig.modelOptions);
|
||||||
|
|
||||||
let modelOptions = _.cloneDeep(resourceConfig.modelOptions);
|
let modelOptions = _.cloneDeep(resourceConfig.modelOptions);
|
||||||
|
@ -128,19 +128,19 @@ class Resources {
|
||||||
modelOptions.limit = options.limit;
|
modelOptions.limit = options.limit;
|
||||||
}
|
}
|
||||||
|
|
||||||
return models.Base.Model.raw_knex.fetchAll(modelOptions)
|
const objects = await models.Base.Model.raw_knex.fetchAll(modelOptions);
|
||||||
.then((objects) => {
|
debug('fetched', resourceConfig.type, objects.length);
|
||||||
debug('fetched', resourceConfig.type, objects.length);
|
|
||||||
|
|
||||||
_.each(objects, (object) => {
|
_.each(objects, (object) => {
|
||||||
this.data[resourceConfig.type].push(new Resource(resourceConfig.type, object));
|
this.data[resourceConfig.type].push(new Resource(resourceConfig.type, object));
|
||||||
});
|
});
|
||||||
|
|
||||||
if (objects.length && isSQLite) {
|
if (objects.length && isSQLite) {
|
||||||
options.offset = options.offset + options.limit;
|
options.offset = options.offset + options.limit;
|
||||||
return this._fetch(resourceConfig, {offset: options.offset, limit: options.limit});
|
return this._fetch(resourceConfig, {offset: options.offset, limit: options.limit});
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
return objects;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Add table
Reference in a new issue