Class: Jobs::CleanUpPostTimings

Inherits:
Onceoff show all
Defined in:
app/jobs/onceoff/clean_up_post_timings.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

Remove post timings that are remnants of previous post moves or other shenanigans and don’t reference a valid user or post anymore.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/jobs/onceoff/clean_up_post_timings.rb', line 7

def execute_onceoff(args)
  DB.exec <<~SQL
    DELETE
    FROM post_timings pt
    WHERE NOT EXISTS(
            SELECT 1
            FROM posts p
            WHERE p.topic_id = pt.topic_id
              AND p.post_number = pt.post_number
        )
  SQL

  DB.exec <<~SQL
    DELETE
    FROM post_timings pt
    WHERE NOT EXISTS(
            SELECT 1
            FROM users u
            WHERE pt.user_id = u.id
        )
  SQL
end