Codeminer42/cm42-central

View on GitHub
lib/tasks/fix_counters.rake

Summary

Maintainability
Test Coverage
desc 'Fix the cache counters'
task fix_counters: :environment do
  Project.find_each do |p|
    p.update(stories_count: p.stories.count, memberships_count: p.users.count)
  end
  User.find_each do |u|
    u.update(memberships_count: u.projects.count)
  end
end