-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -50,18 +50,25 @@ async function deleteSubscriber (email) { | |
| throw err | ||
| } | ||
|
|
||
| for (const list of lists) { | ||
| try { | ||
| await axios.post(`${baseUrl}/lists/${list.id}/members/${subscriberHash}/actions/delete-permanent`, null, { headers }) | ||
| } catch (err) { | ||
| // A 404 means the subscriber was not present in that list, which is fine | ||
| if (err.response && err.response.status === 404) { | ||
| logger.info(`MailChimp subscriber not found in list ${list.id}`) | ||
| } else { | ||
| logger.error(`Failed to delete MailChimp subscriber from list ${list.id}: ${err.message}`) | ||
| throw err | ||
| const deletionResults = await Promise.allSettled( | ||
| lists.map(async (list) => { | ||
| try { | ||
| await axios.post(`${baseUrl}/lists/${list.id}/members/${subscriberHash}/actions/delete-permanent`, null, { headers }) | ||
| } catch (err) { | ||
| // A 404 means the subscriber was not present in that list, which is fine | ||
| if (err.response && err.response.status === 404) { | ||
| logger.info(`MailChimp subscriber not found in list ${list.id}`) | ||
| } else { | ||
| logger.error(`Failed to delete MailChimp subscriber from list ${list.id}: ${err.message}`) | ||
| throw err | ||
| } | ||
| } | ||
| } | ||
| }) | ||
| ) | ||
|
|
||
| const failedDeletion = deletionResults.find((result) => result.status === 'rejected') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| if (failedDeletion) { | ||
| throw failedDeletion.reason | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -657,11 +657,14 @@ async function deleteMember (currentUser, handle, data) { | |
| await skillsPrisma.userSkill.deleteMany({ where: { userId: identityUserId } }) | ||
| await updateIdentityRecords(identityUserId, deletedHandle, deletedEmail, now) | ||
|
|
||
| try { | ||
| await mailchimp.deleteSubscriber(member.email) | ||
| } catch (err) { | ||
| 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 commentThe reason will be displayed to describe this comment to others. Learn more. [ |
||
| try { | ||
| await mailchimp.deleteSubscriber(member.email) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| } catch (err) { | ||
| logger.error(`MailChimp deletion failed for ${member.email}: ${err.message}`) | ||
| } | ||
| })() | ||
|
|
||
| prismaHelper.convertMember(updatedMember) | ||
| await helper.postBusEvent(constants.TOPICS.MemberUpdated, updatedMember) | ||
|
|
||
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.allSettledis 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 theaxios.postcalls throw an error that is not a 404. Consider logging all errors within thecatchblock to ensure no silent failures.