ADD 添加定时更新实践项目的myshixun_count 和averge_star数据排序功能

educoder
jasder duan 1 year ago
parent 95e0d2d368
commit c1a8f932e9

@ -3,7 +3,7 @@
namespace :daily_update_star_for_shixun do namespace :daily_update_star_for_shixun do
desc "update star count every day for shixun " desc "update star count every day for shixun "
task :execute => :environment do task :execute => :environment do
shixuns = Shixun.select("id, averge_star") shixuns = Shixun.select("id, averge_star").order(updated_at: :desc)
shixuns = shixuns.where(id: ENV['shixun_id']) if ENV['shixun_id'].present? 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|

@ -3,7 +3,7 @@
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").group("shixuns.id") shixuns = Shixun.joins(:myshixuns).select("shixuns.id, COUNT(myshixuns.id) AS query_myshixuns_count").group("shixuns.id").order("query_myshixuns_count DESC")
shixuns = shixuns.where(id: ENV['shixun_id']) if ENV['shixun_id'].present? 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|

Loading…
Cancel
Save