From 92a04369e27ec42fcc01cc717737429fa5cefd37 Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Wed, 26 Mar 2025 22:24:53 +0530 Subject: [PATCH] chore: add alternative --- app/services/internal/remove_orphaned_contacts_service.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/services/internal/remove_orphaned_contacts_service.rb b/app/services/internal/remove_orphaned_contacts_service.rb index 793bfbb7b..513cd9f76 100644 --- a/app/services/internal/remove_orphaned_contacts_service.rb +++ b/app/services/internal/remove_orphaned_contacts_service.rb @@ -39,5 +39,12 @@ class Internal::RemoveOrphanedContactsService def base_query account.contacts.where('created_at < ?', Time.zone.now - offset) + + # Alternative + # orphaned_contact_ids = account.contacts + # .left_outer_joins(:conversations) + # .where('contacts.created_at < ?', Time.zone.now - offset) + # .where(conversations: { id: nil }) # Select contacts with no conversations + # .pluck('contacts.id') # Get only the IDs end end