Project

General

Profile

« Previous | Next » 

Revision a152a1b2

Added by Tomer Brisker over 8 years ago

Fixes #11444 - Correctly count hosts in domain

Only hosts that have a primary nic assigned to a domain should be
counted in the domain host count. Previous implementation was flawed in
that it only updated the counter in certain occasions and not all,
leading sometimes to incorrect host counts.
I have implemented the counter updates in `after_commit` to reduce
chance of deadlocks.

View differences:

lib/tasks/fix_cached_counters.rake
desc 'Fix cached counters by reseting them to the correct count, in case they got corrupted somehow'
task :fix_cached_counters => :environment do
puts "Correcting cached counters: (this may take a few minutes)"
[ Architecture, Environment, Operatingsystem, Domain, Realm].each do |cl|
[ Architecture, Environment, Operatingsystem, Realm].each do |cl|
cl.unscoped.all.each{|el| cl.reset_counters(el.id, :hosts, :hostgroups)}
puts "#{cl} corrected"
end
Domain.all.each do |el|
Domain.reset_counters(el.id, :hostgroups)
el.update_attribute('total_hosts', Nic::Base.primary.where(:domain_id => el.id).count)
end
puts "Domains corrected"
Puppetclass.all.each{|el| Puppetclass.reset_counters(el.id, :hostgroup_classes, :lookup_keys)}
puts "Puppetclass corrected"
Model.all.each{|el| Model.reset_counters(el.id, :hosts)}

Also available in: Unified diff