Story #105846070 - use Domain.includes, replace Domain.find; return Relation rather than array. white space changes

This commit is contained in:
Matt Farnsworth 2015-12-14 14:08:52 +02:00
parent 48ab1c7c7e
commit 9d2f23a71d

View file

@ -20,21 +20,19 @@ authentication using electronic ID. Association through a business organisation
class BusinessRegistryCache < ActiveRecord::Base class BusinessRegistryCache < ActiveRecord::Base
def associated_domains def associated_domains
domains = [] domains = []
contact_ids = associated_businesses.map do |bic| contact_ids = associated_businesses.map do |bic|
Contact.select(:id).where("ident = ? AND ident_type = 'org' AND ident_country_code = 'EE'", bic).pluck(:id) Contact.select(:id).where("ident = ? AND ident_type = 'org' AND ident_country_code = 'EE'", bic).pluck(:id)
end end
contact_ids = Contact.select(:id).where("ident = ? AND ident_type = 'priv' AND ident_country_code = ?", contact_ids = Contact.select(:id).where("ident = ? AND ident_type = 'priv' AND ident_country_code = ?",
ident, ident_country_code).pluck(:id) + contact_ids ident, ident_country_code).pluck(:id) + contact_ids
contact_ids.flatten!.compact! unless contact_ids.blank? contact_ids.flatten!.compact! unless contact_ids.blank?
contact_ids.uniq! unless contact_ids.blank? unless contact_ids.blank?
unless contact_ids.blank? contact_ids.uniq!
DomainContact.select(:domain_id).distinct.where("contact_id in (?)", contact_ids).pluck(:domain_id).try(:each) do |domain_id| domains = DomainContact.select(:domain_id).distinct.where("contact_id in (?)", contact_ids).pluck(:domain_id)
domains << Domain.find(domain_id) end
end Domain.includes(:registrar, :registrant).where('id in (?)', domains)
end
domains
end end
class << self class << self