perf: use update_columns for contact last_activity_at
Replace `sender.update(last_activity_at:)` with `update_columns` in Message#update_contact_activity. This runs on every incoming message (3.3M calls/day) and the full ActiveRecord update lifecycle is unnecessary for a single timestamp write: - Skips before_save :sync_contact_attributes (only relevant for email/phone/identifier changes, not last_activity_at) - Skips after_update_commit :dispatch_update_event which fires CONTACT_UPDATED → ActionCable broadcasts, webhook deliveries, and LeadSquared hooks on every incoming message with no meaningful data change - Eliminates 192K seconds/day of DB time from contact UPDATEs that trigger full validation and callback chains
This commit is contained in:
@@ -318,7 +318,9 @@ class Message < ApplicationRecord
|
||||
end
|
||||
|
||||
def update_contact_activity
|
||||
sender.update(last_activity_at: DateTime.now) if sender.is_a?(Contact)
|
||||
# rubocop:disable Rails/SkipsModelValidations
|
||||
sender.update_columns(last_activity_at: DateTime.now) if sender.is_a?(Contact)
|
||||
# rubocop:enable Rails/SkipsModelValidations
|
||||
end
|
||||
|
||||
def update_waiting_since
|
||||
|
||||
Reference in New Issue
Block a user