feat: add job to remove stale contacts and contact_inboxes (#11186)
- Add a job to remove stale contacts and contact_inboxes across all accounts Stale anonymous contact is defined as - have no identification (email, phone_number, and identifier are NULL) - have no conversations - are older than 30 days --------- Co-authored-by: Pranav <pranav@chatwoot.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
@@ -128,6 +128,18 @@ class Contact < ApplicationRecord
|
||||
)
|
||||
}
|
||||
|
||||
# Find contacts that:
|
||||
# 1. Have no identification (email, phone_number, and identifier are NULL or empty string)
|
||||
# 2. Have no conversations
|
||||
# 3. Are older than the specified time period
|
||||
scope :stale_without_conversations, lambda { |time_period|
|
||||
where('contacts.email IS NULL OR contacts.email = ?', '')
|
||||
.where('contacts.phone_number IS NULL OR contacts.phone_number = ?', '')
|
||||
.where('contacts.identifier IS NULL OR contacts.identifier = ?', '')
|
||||
.where('contacts.created_at < ?', time_period)
|
||||
.where.missing(:conversations)
|
||||
}
|
||||
|
||||
def get_source_id(inbox_id)
|
||||
contact_inboxes.find_by!(inbox_id: inbox_id).source_id
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user