mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00: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}
|
||||
* @private
|
||||
*/
|
||||
_fetch(resourceConfig, options = {offset: 0, limit: 999}) {
|
||||
async _fetch(resourceConfig, options = {offset: 0, limit: 999}) {
|
||||
debug('_fetch', resourceConfig.type, resourceConfig.modelOptions);
|
||||
|
||||
let modelOptions = _.cloneDeep(resourceConfig.modelOptions);
|
||||
|
@ -128,19 +128,19 @@ class Resources {
|
|||
modelOptions.limit = options.limit;
|
||||
}
|
||||
|
||||
return models.Base.Model.raw_knex.fetchAll(modelOptions)
|
||||
.then((objects) => {
|
||||
debug('fetched', resourceConfig.type, objects.length);
|
||||
const objects = await models.Base.Model.raw_knex.fetchAll(modelOptions);
|
||||
debug('fetched', resourceConfig.type, objects.length);
|
||||
|
||||
_.each(objects, (object) => {
|
||||
this.data[resourceConfig.type].push(new Resource(resourceConfig.type, object));
|
||||
});
|
||||
_.each(objects, (object) => {
|
||||
this.data[resourceConfig.type].push(new Resource(resourceConfig.type, object));
|
||||
});
|
||||
|
||||
if (objects.length && isSQLite) {
|
||||
options.offset = options.offset + options.limit;
|
||||
return this._fetch(resourceConfig, {offset: options.offset, limit: options.limit});
|
||||
}
|
||||
});
|
||||
if (objects.length && isSQLite) {
|
||||
options.offset = options.offset + options.limit;
|
||||
return this._fetch(resourceConfig, {offset: options.offset, limit: options.limit});
|
||||
}
|
||||
|
||||
return objects;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue