Class: Jobs::RetroRecentTimeRead
- Defined in:
- app/jobs/onceoff/retro_recent_time_read.rb
Instance Method Summary collapse
Methods inherited from Onceoff
enqueue_all, #execute, name_for, #running_key_name
Methods inherited from Base
acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, #execute, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately
Instance Method Details
#execute_onceoff(args) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'app/jobs/onceoff/retro_recent_time_read.rb', line 5 def execute_onceoff(args) # update past records by evenly distributing total time reading among each post read sql = <<~SQL UPDATE user_visits uv1 SET time_read = ( SELECT ( uv1.posts_read / (SELECT CAST(sum(uv2.posts_read) AS FLOAT) FROM user_visits uv2 where uv2.user_id = uv1.user_id) * COALESCE((SELECT us.time_read FROM user_stats us WHERE us.user_id = uv1.user_id), 0) ) ) WHERE EXISTS (SELECT 1 FROM user_stats stats WHERE stats.user_id = uv1.user_id AND stats.posts_read_count > 0 LIMIT 1) AND EXISTS (SELECT 1 FROM user_visits visits WHERE visits.user_id = uv1.user_id AND visits.posts_read > 0 LIMIT 1) SQL DB.exec(sql) end |