0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-24 23:48:13 -05:00

Fixed email batch partitioning when only one card used

refs https://github.com/TryGhost/Team/issues/828

- Previous method had a bug where it didn't take into account cases when onlya single card with a segment filter has been used leaving the members not covered by that filter without an email
This commit is contained in:
Naz 2021-07-01 20:55:43 +04:00
parent 986a7526f5
commit 380c0dad2c

View file

@ -408,20 +408,29 @@ function partitionMembersBySegment(memberRows, segments) {
* @param {Object} options.options - knex options
*/
async function createSegmentedEmailBatches({emailModel, options}) {
let memberRows = await getEmailMemberRows({emailModel, options});
if (!memberRows.length) {
return [];
}
const segments = getSegmentsFromHtml(emailModel.get('html'));
const batchIds = [];
if (segments.length) {
for (const memberSegment of segments) {
const partitionedMembers = partitionMembersBySegment(memberRows, segments);
for (const partition in partitionedMembers) {
const emailBatchIds = await createEmailBatches({
emailModel,
memberSegment,
memberRows: partitionedMembers[partition],
memberSegment: partition === 'unsegmented' ? null : partition,
options
});
batchIds.push(emailBatchIds);
}
} else {
const emailBatchIds = await createEmailBatches({emailModel, options});
const emailBatchIds = await createEmailBatches({emailModel, memberRows, options});
batchIds.push(emailBatchIds);
}
@ -436,16 +445,11 @@ async function createSegmentedEmailBatches({emailModel, options}) {
* @param {Object} options
* @param {Object} options.emailModel - instance of Email model
* @param {string} [options.memberSegment] - NQL filter to apply in addition to the one defined in emailModel
* @param {Object[]} [options.memberRows] - member rows to be batched
* @param {Object} options.options - knex options
* @returns {Promise<string[]>} - created batch ids
*/
async function createEmailBatches({emailModel, memberSegment, options}) {
const memberRows = await getEmailMemberRows({emailModel, memberSegment, options});
if (!memberRows.length) {
return [];
}
async function createEmailBatches({emailModel, memberRows, memberSegment, options}) {
const storeRecipientBatch = async function (recipients) {
const knexOptions = _.pick(options, ['transacting', 'forUpdate']);
const batchModel = await models.EmailBatch.add({