mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-28 05:14:12 +03:00
d2cb23c3fa
ref PROD-233 - Stored whether Docker is used in the config files - When running `yarn setup`, any existing Docker container will be reset. Run with `-y` to skip the confirmation step. - `yarn setup` will always init the database and generate fake data - Increased amount of default generated data to 100,000 members + 500 posts. - Made lots of performance improvements in the data generator so we can generate the default data in ±170s
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const TableImporter = require('./TableImporter');
|
|
const {faker} = require('@faker-js/faker');
|
|
const {luck} = require('../utils/random');
|
|
|
|
class MembersLabelsImporter extends TableImporter {
|
|
static table = 'members_labels';
|
|
static dependencies = ['labels', 'members'];
|
|
|
|
constructor(knex, transaction, {labels}) {
|
|
super(MembersLabelsImporter.table, knex, transaction);
|
|
this.labels = labels;
|
|
}
|
|
|
|
async import(quantity) {
|
|
const members = await this.transaction.select('id').from('members');
|
|
this.labels = await this.transaction.select('id').from('labels');
|
|
|
|
await this.importForEach(members, quantity ? quantity / members.length : 1);
|
|
}
|
|
|
|
generate() {
|
|
if (luck(90)) {
|
|
// 90% of members don't have labels
|
|
return;
|
|
}
|
|
// TODO: Ensure we don't generate the same member label twice
|
|
return {
|
|
id: this.fastFakeObjectId(),
|
|
member_id: this.model.id,
|
|
label_id: this.labels[faker.datatype.number({
|
|
min: 0,
|
|
max: this.labels.length - 1
|
|
})].id,
|
|
sort_order: 0
|
|
};
|
|
}
|
|
}
|
|
|
|
module.exports = MembersLabelsImporter;
|