Sha256: 6e77fce1705d6de82d7697eaa795389f9818b61883884efcbf674695886e6350

Contents?: true

Size: 499 Bytes

Versions: 12

Compression:

Stored size: 499 Bytes

Contents

desc "Update counter caches"
task :update_counter_caches => :environment do
  # Update the Venue#events_count
  total = Calagator::Venue.count
  Calagator::Venue.all.each do |venue|
    cached = venue.events_count
    actual = venue.events.count
    if actual != cached
      puts "Updating Venue ##{venue.id} from #{cached} cached to #{actual} actual -- #{venue.title}"
      Calagator::Venue.connection.update("UPDATE venues SET events_count = #{actual} WHERE id = #{venue.id}")
    end
  end
end

Version data entries

12 entries across 12 versions & 2 rubygems

Version Path
calagator-1.0.0 lib/tasks/update_counter_caches.rake
grokus-1.0.0.9 lib/tasks/update_counter_caches.rake
grokus-1.0.0.8 lib/tasks/update_counter_caches.rake
grokus-1.0.0.7 lib/tasks/update_counter_caches.rake
grokus-1.0.0.6 lib/tasks/update_counter_caches.rake
grokus-1.0.0.5 lib/tasks/update_counter_caches.rake
grokus-1.0.0.3 lib/tasks/update_counter_caches.rake
grokus-1.0.0.2 lib/tasks/update_counter_caches.rake
grokus-1.0.0.1 lib/tasks/update_counter_caches.rake
calagator-1.0.0.rc3 lib/tasks/update_counter_caches.rake
calagator-1.0.0.rc2 lib/tasks/update_counter_caches.rake
calagator-1.0.0.rc1 lib/tasks/update_counter_caches.rake