mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Fixed early return when there are no new email batches
- the code in question had the intention of returning early if no new email batches had been created for an Email - there were 2 minor bugs here: - `batchIds` would end up being an array of an array of strings because we just push an array in without the spread operator - we would compare that the returned array equaled zero, which was never the case - this commit fixes these minor issues and adds JSDoc to document the function's return type
This commit is contained in:
parent
fcd6360869
commit
8e3b611606
1 changed files with 7 additions and 4 deletions
|
@ -306,10 +306,11 @@ async function sendEmailJob({emailModel, options}) {
|
|||
const existingBatchCount = await emailModel.related('emailBatches').count('id');
|
||||
|
||||
if (existingBatchCount === 0) {
|
||||
let newBatchCount;
|
||||
let newBatchCount = 0;
|
||||
|
||||
await models.Base.transaction(async (transacting) => {
|
||||
newBatchCount = await createSegmentedEmailBatches({emailModel, options: {transacting}});
|
||||
const emailBatches = await createSegmentedEmailBatches({emailModel, options: {transacting}});
|
||||
newBatchCount = emailBatches.length;
|
||||
});
|
||||
|
||||
if (newBatchCount === 0) {
|
||||
|
@ -423,6 +424,8 @@ function partitionMembersBySegment(memberRows, segments) {
|
|||
* @param {Object} options
|
||||
* @param {Object} options.emailModel - instance of Email model
|
||||
* @param {Object} options.options - knex options
|
||||
*
|
||||
* @returns {Promise<string[]>}
|
||||
*/
|
||||
async function createSegmentedEmailBatches({emailModel, options}) {
|
||||
let memberRows = await getEmailMemberRows({emailModel, options});
|
||||
|
@ -444,11 +447,11 @@ async function createSegmentedEmailBatches({emailModel, options}) {
|
|||
memberSegment: partition === 'unsegmented' ? null : partition,
|
||||
options
|
||||
});
|
||||
batchIds.push(emailBatchIds);
|
||||
batchIds.push(...emailBatchIds);
|
||||
}
|
||||
} else {
|
||||
const emailBatchIds = await createEmailBatches({emailModel, memberRows, options});
|
||||
batchIds.push(emailBatchIds);
|
||||
batchIds.push(...emailBatchIds);
|
||||
}
|
||||
|
||||
return batchIds;
|
||||
|
|
Loading…
Add table
Reference in a new issue