-
Notifications
You must be signed in to change notification settings - Fork 3
Mailchimp performance update #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| } else { | ||
| logger.error(`Failed to delete MailChimp subscriber from list ${list.id}: ${err.message}`) | ||
| throw err | ||
| const deletionResults = await Promise.allSettled( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[correctness]
Using Promise.allSettled is a good choice for handling multiple promises where you want to continue processing even if some fail. However, be cautious about the potential for unhandled promise rejections if any of the axios.post calls throw an error that is not a 404. Consider logging all errors within the catch block to ensure no silent failures.
| }) | ||
| ) | ||
|
|
||
| const failedDeletion = deletionResults.find((result) => result.status === 'rejected') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[maintainability]
The current implementation only throws the first error encountered in failedDeletion. If multiple deletions fail, you might miss other errors. Consider logging all errors or aggregating them to provide a complete picture of what went wrong.
| logger.error(`MailChimp deletion failed for ${member.email}: ${err.message}`) | ||
| } | ||
| // Kick off MailChimp deletion without blocking the API response. | ||
| ;(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[readability]
The use of an immediately invoked function expression (IIFE) to perform an asynchronous operation is unconventional and may lead to confusion. Consider using a named async function or a promise-based approach to improve readability and maintainability.
| // Kick off MailChimp deletion without blocking the API response. | ||
| ;(async () => { | ||
| try { | ||
| await mailchimp.deleteSubscriber(member.email) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗ correctness]
The member.email variable is used within the asynchronous function, which may lead to unexpected behavior if member is modified elsewhere before the function executes. Consider capturing member.email in a local variable before the IIFE to ensure the correct value is used.
No description provided.