Class: Jobs::InitCategoryTagStats

Inherits:
Onceoff show all
Defined in:
app/jobs/onceoff/init_category_tag_stats.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
# File 'app/jobs/onceoff/init_category_tag_stats.rb', line 5

def execute_onceoff(args)
  DB.exec "DELETE FROM category_tag_stats"

  DB.exec <<~SQL
INSERT INTO category_tag_stats (category_id, tag_id, topic_count)
     SELECT topics.category_id, tags.id, COUNT(topics.id)
       FROM tags
 INNER JOIN topic_tags ON tags.id = topic_tags.tag_id
 INNER JOIN topics ON topics.id = topic_tags.topic_id
        AND topics.deleted_at IS NULL
        AND topics.category_id IS NOT NULL
   GROUP BY tags.id, topics.category_id
  SQL
end