iachat/app/jobs
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
..
account feat: Contact Exports (#7258) 2023-06-13 09:18:43 +05:30
agent_bots chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
agents chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
avatar chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
campaigns chore: one off SMS campaign APIs (#2589) 2021-07-14 12:24:09 +05:30
channels/whatsapp chore: Improve Whatsapp Templates Sync (#7210) 2023-05-29 22:23:22 +05:30
conversations chore: Update MarkMessagesAsReadJob to accept delivered status (#8319) 2023-11-08 13:44:57 -08:00
inboxes fix: Optimize email fetching logic to fix bandwidth exceeded issues (#8730) 2024-01-18 11:45:16 +04:00
internal chore: Update self-hosted billing redirect (#8580) 2023-12-18 16:34:47 -08:00
labels fix: Update associations when a label is updated (#3046) 2021-09-21 10:16:32 +05:30
migration chore(migration): Re-run database migration job for caching. (#8581) 2023-12-18 17:29:02 -08:00
notification chore: Get all notification API improvments (#8549) 2024-01-17 09:02:18 +05:30
webhooks feat: Facebook delivery reports (#8136) 2023-11-20 12:22:45 +05:30
action_cable_broadcast_job.rb chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
application_job.rb Chore: Fix Deserialisation Error in Jobs (#1683) 2021-01-31 13:05:07 +05:30
bulk_actions_job.rb fix: Added "None" option in bulk actions assignment menu (#5585) 2022-10-11 13:44:35 -07:00
contact_ip_lookup_job.rb feat(poc): Disable widget based on country (#6658) 2023-03-14 09:09:57 -07:00
data_import_job.rb fix: Handle Contact import MalformedCSVError (#8706) 2024-01-18 13:05:58 +05:30
delete_object_job.rb fix: capture user and ip details on Inbox delete (#7395) 2023-06-27 19:49:24 +05:30
event_dispatcher_job.rb chore: Reorganize Sidekiq Queues (#6976) 2023-05-04 15:44:16 +05:30
hook_job.rb feat: Update the slack integration-flow to allow users to select the channel (#7637) 2023-07-28 14:50:30 -07:00
macros_execution_job.rb feat: Execute macro actions, for the conversation (#5066) 2022-07-26 12:41:22 +05:30
mutex_application_job.rb feat: implement mutex for SlackSendJob (#7783) 2023-08-25 11:58:29 +07:00
send_on_slack_job.rb feat: set lock timeout to 1 second (#8661) 2024-01-12 08:28:07 +05:30
send_reply_job.rb chore: Provider APIs for SMS Channel - Bandwidth (#3889) 2022-02-03 15:22:13 -08:00
slack_unfurl_job.rb feat: Support link unfurling for all the channels within the same connected channel account. (#8033) 2023-10-08 17:55:03 +05:30
trigger_scheduled_items_job.rb feat: Add a job to reopen snoozed notifications (#8545) 2024-01-05 15:13:22 +05:30
webhook_job.rb feat: Mark the messages as failed if the API channel webhooks fail for any reason. (#8277) 2023-11-04 12:26:28 +05:30