From 39e246aaf842f103d12ac84ff2bb1e3d8a71ce44 Mon Sep 17 00:00:00 2001 From: Halldor Thorhallsson Date: Fri, 21 Oct 2022 13:08:44 -0400 Subject: [PATCH] Removed bluebird from fixture-manager.js (#15629) refs: https://github.com/TryGhost/Ghost/issues/14882 - Removing bluebird specific methods in favour of the Ghost sequence method so we can remove the bluebird dependency Co-authored-by: Hannah Wolfe --- .../data/schema/fixtures/fixture-manager.js | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/ghost/core/core/server/data/schema/fixtures/fixture-manager.js b/ghost/core/core/server/data/schema/fixtures/fixture-manager.js index cb67a831b7..02f86c1d3e 100644 --- a/ghost/core/core/server/data/schema/fixtures/fixture-manager.js +++ b/ghost/core/core/server/data/schema/fixtures/fixture-manager.js @@ -1,5 +1,4 @@ const _ = require('lodash'); -const Promise = require('bluebird'); const logging = require('@tryghost/logging'); const {sequence} = require('@tryghost/promise'); @@ -83,16 +82,16 @@ class FixtureManager { const userRolesRelation = this.fixtures.relations.find(r => r.from.relation === 'roles'); await this.addFixturesForRelation(userRolesRelation, localOptions); - await Promise.mapSeries(this.fixtures.models.filter(m => !['User', 'Role'].includes(m.name)), (model) => { + await sequence(this.fixtures.models.filter(m => !['User', 'Role'].includes(m.name)).map(model => () => { logging.info('Model: ' + model.name); return this.addFixturesForModel(model, localOptions); - }); + })); - await Promise.mapSeries(this.fixtures.relations.filter(r => r.from.relation !== 'roles'), (relation) => { + await sequence(this.fixtures.relations.filter(r => r.from.relation !== 'roles').map(relation => () => { logging.info('Relation: ' + relation.from.model + ' to ' + relation.to.model); return this.addFixturesForRelation(relation, localOptions); - }); + })); } /* @@ -191,12 +190,15 @@ class FixtureManager { fetchRelationData(relation, options) { const fromOptions = _.extend({}, options, {withRelated: [relation.from.relation]}); - const props = { - from: models[relation.from.model].findAll(fromOptions), - to: models[relation.to.model].findAll(options) - }; + const fromRelations = models[relation.from.model].findAll(fromOptions); + const toRelations = models[relation.to.model].findAll(options); - return Promise.props(props); + return Promise.all([fromRelations, toRelations]).then(([from, to]) => { + return { + from: from, + to: to + }; + }); } /** @@ -223,7 +225,7 @@ class FixtureManager { }); } - const results = await Promise.mapSeries(modelFixture.entries, async (entry) => { + const results = await sequence(modelFixture.entries.map(entry => async () => { let data = {}; // CASE: if id is specified, only query by id @@ -243,7 +245,7 @@ class FixtureManager { if (!found) { return models[modelFixture.name].add(entry, options); } - }); + })); return {expected: modelFixture.entries.length, done: _.compact(results).length}; } @@ -308,12 +310,12 @@ class FixtureManager { } async removeFixturesForModel(modelFixture, options) { - const results = await Promise.mapSeries(modelFixture.entries, async (entry) => { + const results = await sequence(modelFixture.entries.map(entry => async () => { const found = models[modelFixture.name].findOne(entry.id ? {id: entry.id} : entry, options); if (found) { return models[modelFixture.name].destroy(_.extend(options, {id: found.id})); } - }); + })); return {expected: modelFixture.entries.length, done: results.length}; }