Class: Jobs::CleanUpTags

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

Constant Summary collapse

GRACE_PERIOD_MINUTES =
5

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



9
10
11
12
13
14
15
16
17
18
19
# File 'app/jobs/scheduled/clean_up_tags.rb', line 9

def execute(args)
  return unless SiteSetting.automatically_clean_unused_tags
  Tag.transaction do
    tags = Tag.unused.where("tags.created_at < ?", GRACE_PERIOD_MINUTES.minutes.ago)
    StaffActionLogger.new(Discourse.system_user).log_custom(
      "deleted_unused_tags",
      tags: tags.pluck(:name),
    )
    tags.destroy_all
  end
end