diff --git a/app/jobs/company_register_status_job.rb b/app/jobs/company_register_status_job.rb index dc40d2d8b..5c070c629 100644 --- a/app/jobs/company_register_status_job.rb +++ b/app/jobs/company_register_status_job.rb @@ -45,12 +45,14 @@ class CompanyRegisterStatusJob < ApplicationJob end def sampling_registrant_contact(days_interval) - Registrant.where(ident_type: 'org', ident_country_code: 'EE').where( - "(company_register_status IS NULL OR checked_company_at IS NULL) OR - (company_register_status = ? AND checked_company_at < ?) OR - company_register_status IN (?)", - Contact::REGISTERED, days_interval.days.ago, [Contact::LIQUIDATED, Contact::BANKRUPT, Contact::DELETED] - ) + Contact.joins(:registrant_domains) + .where(ident_type: 'org', ident_country_code: 'EE') + .where( + "(company_register_status IS NULL OR checked_company_at IS NULL) OR + (company_register_status = ? AND checked_company_at < ?) OR + company_register_status IN (?)", + Contact::REGISTERED, 365.days.ago, [Contact::LIQUIDATED, Contact::BANKRUPT, Contact::DELETED] + ).distinct end def update_validation_company_status(contact:, status:)