0
Fork 0
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:
Daniel Lockyer 2024-10-14 09:48:02 +02:00 committed by Daniel Lockyer
parent df76883378
commit b0cf15cb94

View file

@ -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;
} }
/** /**