Fixed generating multiple members_newsletters records
refs https://github.com/TryGhost/DevOps/issues/119 - members_newsletters needs members_subscribe_events, but it was also then generating `subscriptions` records and the whole thing was really slow - for now, subscriptions is not a used table so we can remove use of it - also adds support for generating more than one subscription record with an 80% chance of being subscribed
This commit is contained in:
parent
db16e565bc
commit
845d3cf759
@ -5,7 +5,7 @@ const dateToDatabaseString = require('../utils/database-date');
|
||||
|
||||
class MembersSubscribeEventsImporter extends TableImporter {
|
||||
static table = 'members_subscribe_events';
|
||||
static dependencies = ['members', 'newsletters', 'subscriptions'];
|
||||
static dependencies = ['members', 'newsletters'/*, 'subscriptions'*/];
|
||||
|
||||
constructor(knex, transaction) {
|
||||
super(MembersSubscribeEventsImporter.table, knex, transaction);
|
||||
@ -14,9 +14,9 @@ class MembersSubscribeEventsImporter extends TableImporter {
|
||||
async import(quantity) {
|
||||
const members = await this.transaction.select('id', 'created_at', 'status').from('members');
|
||||
this.newsletters = await this.transaction.select('id').from('newsletters').orderBy('sort_order');
|
||||
this.subscriptions = await this.transaction.select('member_id', 'created_at').from('subscriptions');
|
||||
//this.subscriptions = await this.transaction.select('member_id', 'created_at').from('subscriptions');
|
||||
|
||||
await this.importForEach(members, quantity ? quantity / members.length : 2);
|
||||
await this.importForEach(members, quantity ? quantity / members.length : this.newsletters.length);
|
||||
}
|
||||
|
||||
setReferencedModel(model) {
|
||||
@ -32,22 +32,15 @@ class MembersSubscribeEventsImporter extends TableImporter {
|
||||
return null;
|
||||
}
|
||||
|
||||
let createdAt = dateToDatabaseString(faker.date.between(new Date(this.model.created_at), new Date()));
|
||||
let subscribed = luck(80);
|
||||
|
||||
// Free newsletter by default
|
||||
let newsletterId = this.newsletters[1].id;
|
||||
if (this.model.status === 'paid' && count === 0) {
|
||||
// Paid newsletter
|
||||
newsletterId = this.newsletters[0].id;
|
||||
createdAt = this.subscriptions.find(s => s.member_id === this.model.id).created_at;
|
||||
subscribed = luck(98);
|
||||
}
|
||||
|
||||
if (!subscribed) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const createdAt = dateToDatabaseString(faker.date.between(new Date(this.model.created_at), new Date()));
|
||||
const newsletterId = this.newsletters[count % this.newsletters.length].id;
|
||||
|
||||
return {
|
||||
id: faker.database.mongodbObjectId(),
|
||||
member_id: this.model.id,
|
||||
|
Loading…
Reference in New Issue
Block a user