mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
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 <github.erisds@gmail.com>
This commit is contained in:
parent
a79c48e547
commit
39e246aaf8
1 changed files with 16 additions and 14 deletions
|
@ -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};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue