Fix email tool slowness by optimizing the update query #127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
This change has been running in Magenta’s production environment for the past two weeks (as of the time of writing) without any issues.
Problem
The email tool was experiencing significant slowness (5–10 seconds delay) after successfully sending emails. Users were seeing a loading screen for an extended period while the email status was being updated, creating a poor user experience.
Root Cause
The
EmailManager.updateEmailStatus()method was usingemailLogDao.merge(), which forced Hibernate to re-write large BLOB fields (body,encryptedMessage,internalComment) and eagerly merge related attachments (emailAttachments), even though onlystatus,errorMessage, andtimestampneeded to be updated.Solution
updateEmailStatus()method inEmailLogDaothat performs a JPQL bulk update (updates onlystatus,errorMessage, andtimestamp)merge()call inEmailManager.updateEmailStatus()with this optimized JPQL update methodOutcome