feat: Add job to remove stale contact inboxes (#8096)

This commit is contained in:
Vishnu Narayanan
2023-11-07 09:54:30 +05:30
committed by GitHub
parent abbb4180ea
commit 677888bcde
6 changed files with 106 additions and 0 deletions

View File

@@ -33,6 +33,13 @@ class ContactInbox < ApplicationRecord
has_many :conversations, dependent: :destroy_async
# contact_inboxes that are not associated with any conversation
scope :stale_without_conversations, lambda { |time_period|
left_joins(:conversations)
.where('contact_inboxes.created_at < ?', time_period)
.where(conversations: { contact_id: nil })
}
def webhook_data
{
id: id,