iachat/app
Pranav Raj S fdbb3bf4b1
fix: Optimize email fetching logic to fix bandwidth exceeded issues (#8730)
The Inboxes::FetchImapEmailsJob is designed to fetch the entire email object and check if its message id is already in the database. However, this process is resource-intensive and time-consuming, as fetching the full email object takes a significant amount of time.

On average, fetching 100 emails can take approximately 3-4 minutes to complete depending on the IMAP server. Since we are not using server flags to identify which emails have already been fetched (to avoid compatibility issues with flags in different email services), we have to fetch all previously available emails. Currently we fetch all the messages that were created from yesterday. This becomes problematic with services like Gmail, which throttle requests based on bandwidth usage.

To address this issue, I have updated the logic as follows:

Fetch the sequence IDs of all the mails in the "Inbox" that were created from yesterday.
Use the FETCH command to fetch only the message-ids using BODY.PEEK[HEADER.FIELDS (MESSAGE-ID)] with the sequence IDs we got in the previous step. This is a faster operation with lower bandwidth usage, as it only returns the sequence ID and message ID.
Check if the message IDs are already present in the database for the selected inbox.
If not present, fetch the entire email object using the FETCH command and create the message.
If the message ID is already present, ignore it and move on to the next message-id.
I have also addressed the issue of duplicate emails appearing in conversations when two fetch email jobs occur simultaneously. I have added a lock for the channel to ensure that the job gracefully exits without waiting for the current job to complete.

Fixes #7247
Fixes #6082
Fixes #8314

Co-authored-by: Sojan <sojan@pepalo.com>
2024-01-18 11:45:16 +04:00
..
actions fix: Stop overwritting contact avatars unneccesarily (#8710) 2024-01-16 16:38:46 +04:00
assets feat: Super admin design improvements (#8517) 2023-12-08 19:40:35 -08:00
builders chore: Get all notification API improvments (#8549) 2024-01-17 09:02:18 +05:30
channels chore: Sentry issues (#4623) 2022-05-06 14:50:55 +05:30
controllers fix: Notification count is incorrect when the number of notifications exceeds the page size. (#8723) 2024-01-17 15:14:37 +04:00
dashboards feat: Super admin design improvements (#8517) 2023-12-08 19:40:35 -08:00
dispatchers Chore: clean up Reporting Events (#4044) 2022-02-28 18:16:12 +05:30
drops feat: Add the support for custom attributes in message variables (#8511) 2023-12-08 14:13:35 -08:00
fields feat: Supports masking tokens in super admin (#6491) 2023-02-21 17:50:55 +05:30
finders chore: Get all notification API improvments (#8549) 2024-01-17 09:02:18 +05:30
helpers fix: Undefined method `length' for nil:NilClass (#8491) 2023-12-05 16:34:29 +05:30
javascript feat: Show notification last active time instead of created time (#8724) 2024-01-18 09:41:53 +05:30
jobs fix: Optimize email fetching logic to fix bandwidth exceeded issues (#8730) 2024-01-18 11:45:16 +04:00
listeners chore: Get all notification API improvments (#8549) 2024-01-17 09:02:18 +05:30
mailboxes chore: Update the error message to the correct one (#8646) 2024-01-11 17:38:38 -08:00
mailers fix: Handle Contact import MalformedCSVError (#8706) 2024-01-18 13:05:58 +05:30
models chore: Switch to Markdown instead of MarkdownV2 for telegram channel (#8720) 2024-01-17 14:28:13 +05:30
policies feat: trigger handoff when agent bot is the actor (#8639) 2024-01-05 15:26:52 -08:00
presenters feat: Add inbox webhook events (#8006) 2023-09-28 15:28:10 -07:00
services feat: log errors on automation filter (#8702) 2024-01-16 16:13:57 +05:30
views fix: Handle Contact import MalformedCSVError (#8706) 2024-01-18 13:05:58 +05:30
workers fix: Update auto reply and hide reply time for email inbox (#3985) 2022-02-15 17:11:28 +05:30
test-matchers.js Initial testing with jest (#133) 2019-10-15 00:18:46 +05:30