|
|
@ -3,8 +3,8 @@
|
|
|
|
namespace :update_myshixuns_count_for_shixun do
|
|
|
|
namespace :update_myshixuns_count_for_shixun do
|
|
|
|
desc "update myshixuns count for shixun every day"
|
|
|
|
desc "update myshixuns count for shixun every day"
|
|
|
|
task :execute => :environment do
|
|
|
|
task :execute => :environment do
|
|
|
|
shixuns = Shixun.joins(:myshixuns).select("shixuns.id, COUNT(myshixuns.id) AS query_myshixuns_count")
|
|
|
|
shixuns = Shixun.joins(:myshixuns).select("shixuns.id, COUNT(myshixuns.id) AS query_myshixuns_count").group("shixuns.id")
|
|
|
|
.group("shixuns.id")
|
|
|
|
shixuns = shixuns.where(id: ENV['shixun_id']) if ENV['shixun_id'].present?
|
|
|
|
|
|
|
|
|
|
|
|
shixuns.find_in_batches(batch_size: 10000) do |group|
|
|
|
|
shixuns.find_in_batches(batch_size: 10000) do |group|
|
|
|
|
update_sql = "UPDATE shixuns SET myshixuns_count = CASE id "
|
|
|
|
update_sql = "UPDATE shixuns SET myshixuns_count = CASE id "
|
|
|
|