Class: Jobs::CleanUpInactiveUsers

Inherits:
Scheduled show all
Defined in:
app/jobs/scheduled/clean_up_inactive_users.rb

Instance Method Summary collapse

Methods inherited from Scheduled

#perform

Methods inherited from Base

acquire_cluster_concurrency_lock!, clear_cluster_concurrency_lock!, cluster_concurrency, cluster_concurrency_redis_key, delayed_perform, #error_context, get_cluster_concurrency, #last_db_duration, #log, #perform, #perform_immediately

Instance Method Details

#execute(args) ⇒ Object



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

def execute(args)
  return if SiteSetting.clean_up_inactive_users_after_days <= 0

  User
    .where(
      last_posted_at: nil,
      trust_level: TrustLevel.levels[:newuser],
      admin: false,
      moderator: false,
    )
    .where("users.created_at < ?", SiteSetting.clean_up_inactive_users_after_days.days.ago)
    .where(
      "users.last_seen_at < ? OR users.last_seen_at IS NULL",
      SiteSetting.clean_up_inactive_users_after_days.days.ago,
    )
    .where
    .missing(:posts, :topics)
    .limit(1000)
    .pluck(:id)
    .each_slice(50) { |slice| destroy(slice) }
end