fix: Force account_id in the query (#13388)
### What Forces `account_id` to be applied consistently in queries and message creation paths. ### Why Some queries were missing `account_id`, leading to cross-account scans and slow performance in large datasets. ### Changes * Added `account_id` to the relevant query columns. * Ensured messages are always created within the correct account scope. * Updated `created_at` handling where required for consistency. ### Impact * Prevents cross-account queries. * Improves query performance. * Reduces risk of incorrect data access across accounts. ### Notes No functional behavior change for end users. This is a performance and safety fix.
This commit is contained in:
@@ -114,7 +114,7 @@ class Message < ApplicationRecord
|
||||
|
||||
scope :created_since, ->(datetime) { where('created_at > ?', datetime) }
|
||||
scope :chat, -> { where.not(message_type: :activity).where(private: false) }
|
||||
scope :non_activity_messages, -> { where.not(message_type: :activity).reorder('id desc') }
|
||||
scope :non_activity_messages, -> { where.not(message_type: :activity).reorder('created_at desc') }
|
||||
scope :today, -> { where("date_trunc('day', created_at) = ?", Date.current) }
|
||||
scope :voice_calls, -> { where(content_type: :voice_call) }
|
||||
|
||||
|
||||
@@ -65,6 +65,6 @@ class Conversations::MessageWindowService
|
||||
end
|
||||
|
||||
def last_incoming_message
|
||||
@last_incoming_message ||= @conversation.messages&.incoming&.last
|
||||
@last_incoming_message ||= @conversation.messages.where(account_id: @conversation.account_id).incoming&.last
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user