fix(contacts): enqueue avatar sync after commit (#15402)
Contact avatars could be skipped when an avatar job was enqueued while the contact record was still inside an open database transaction. A fast worker could pick up the job before the record became visible and discard it after deserialization failed. This change makes avatar URL jobs wait for the surrounding transaction to commit before they enter the queue. Avatar jobs scheduled outside a transaction continue to enqueue immediately, and the existing download, validation, and rate-limiting behavior remains unchanged. Fixes https://linear.app/chatwoot/issue/CW-7917/facebook-contact-avatars-never-sync-avatarfromurljob-is-enqueued ### How to reproduce 1. Receive a Facebook message from a sender who does not yet exist as a contact. 2. Let the message flow create the contact and schedule its avatar job within the same transaction. 3. Observe that a worker can attempt to deserialize the contact before the transaction commits, causing the avatar job to be discarded. ### How to test 1. Receive a Facebook message from a new sender with a profile picture. 2. Confirm the contact and conversation are created successfully. 3. Confirm the avatar job is enqueued after the transaction commits and the profile picture is attached. 4. Create a contact with an avatar through the Contacts API and confirm the same behavior. --------- Co-authored-by: Muhsin <12408980+muhsin-k@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
# there is a change in the underlying asset.
|
||||
# - A 1 minute rate limit window is enforced via `last_avatar_sync_at`.
|
||||
class Avatar::AvatarFromUrlJob < ApplicationJob
|
||||
self.enqueue_after_transaction_commit = true
|
||||
|
||||
include UrlHelper
|
||||
queue_as :purgable
|
||||
|
||||
|
||||
Reference in New Issue
Block a user