Ghost/ghost/data-generator/lib/importers/MembersNewslettersImporter.js
Simon Backx 285a684ef6
Updated data generator to support >2M members (#19484)
no issue

The data generator went out of memory when trying to generate fake data
for > 2M members. This adds some improvements to make sure it doesn't go
out of memory.

---------

Co-authored-by: Fabien "egg" O'Carroll <fabien@allou.is>
2024-01-15 15:23:49 +00:00

39 lines
1.1 KiB
JavaScript

const TableImporter = require('./TableImporter');
class MembersNewslettersImporter extends TableImporter {
static table = 'members_newsletters';
static dependencies = ['members_subscribe_events'];
constructor(knex, transaction) {
super(MembersNewslettersImporter.table, knex, transaction);
}
async import(quantity) {
let offset = 0;
let limit = 100000;
// eslint-disable-next-line no-constant-condition
while (true) {
const membersSubscribeEvents = await this.transaction.select('member_id', 'newsletter_id').from('members_subscribe_events').limit(limit).offset(offset);
if (membersSubscribeEvents.length === 0) {
break;
}
await this.importForEach(membersSubscribeEvents, quantity ? quantity / membersSubscribeEvents.length : 1);
offset += limit;
}
}
generate() {
return {
id: this.fastFakeObjectId(),
member_id: this.model.member_id,
newsletter_id: this.model.newsletter_id
};
}
}
module.exports = MembersNewslettersImporter;