Optimize contact linked status update #2477

This commit is contained in:
Priit Tark 2015-07-23 20:02:01 +03:00
parent 8700beea60
commit 48bc4d4ac9
3 changed files with 48 additions and 19 deletions

View file

@ -16,10 +16,20 @@ class Epp::Domain < Domain
false
end
before_save :update_contact_status
def update_contact_status
contacts.each do |c|
next if c.linked?
before_save :link_contacts
def link_contacts
# Based on bullet report
unlinked_contacts = contacts.select { |c| !c.linked? } # speed up a bit
unlinked_contacts.each do |uc|
uc.domains_present = true # no need to fetch domains again
uc.save(validate: false)
end
end
after_destroy :unlink_contacts
def unlink_contacts
contacts.each do |c|
c.domains_present = false
c.save(validate: false)
end
end