Merge pull request #3116 from consul/backport-1759-most_active_score_daily_update

[Backport] Optimize task reset_hot_score
This commit is contained in:
Julian Nicolas Herrero
2018-12-19 17:29:09 +01:00
committed by GitHub
2 changed files with 9 additions and 2 deletions

View File

@@ -26,3 +26,7 @@ end
every 1.day, at: '5:00 am' do
rake "-s sitemap:refresh"
end
every 1.day, at: '3:00 am', roles: [:cron] do
rake "votes:reset_hot_score"
end

View File

@@ -18,10 +18,13 @@ namespace :votes do
models = [Debate, Proposal, Legislation::Proposal]
models.each do |model|
print "Updating votes hot_score for #{model}s"
model.find_each do |resource|
resource.save
print "."
end
end
new_hot_score = resource.calculate_hot_score
resource.update_columns(hot_score: new_hot_score, updated_at: Time.current)
end
puts ""
end
puts "Task finished 🎉 "
end
end