Ghost/ghost/data-generator/lib/importers/EmailBatchesImporter.js
Simon Backx d2cb23c3fa
Wired up Docker setup script and increased data generation performance (#19420)
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
2024-01-05 13:42:30 +00:00

39 lines
1.4 KiB
JavaScript

const TableImporter = require('./TableImporter');
const {faker} = require('@faker-js/faker');
const dateToDatabaseString = require('../utils/database-date');
class EmailBatchesImporter extends TableImporter {
static table = 'email_batches';
static dependencies = ['emails'];
constructor(knex, transaction) {
super(EmailBatchesImporter.table, knex, transaction);
}
async import(quantity) {
const emails = await this.transaction.select('id', 'created_at', 'email_count').from('emails');
// 1 batch per 1000 recipients
await this.importForEach(emails, quantity ?? (() => {
return Math.ceil(this.model.email_count / 1000);
}));
}
generate() {
const emailSentDate = new Date(this.model.created_at);
const latestUpdatedDate = new Date(this.model.created_at);
latestUpdatedDate.setHours(latestUpdatedDate.getHours() + 1);
return {
id: this.fastFakeObjectId(),
email_id: this.model.id,
provider_id: `${new Date().toISOString().split('.')[0].replace(/[^0-9]/g, '')}.${faker.datatype.hexadecimal({length: 16, prefix: '', case: 'lower'})}@m.example.com`,
status: 'submitted', // TODO: introduce failures
created_at: this.model.created_at,
updated_at: dateToDatabaseString(faker.date.between(emailSentDate, latestUpdatedDate))
};
}
}
module.exports = EmailBatchesImporter;