Class: RemoveUnusedTagsJob

Inherits:
ContainerBrokerBaseJob show all
Defined in:
app/jobs/remove_unused_tags_job.rb

Constant Summary

Constants inherited from ContainerBrokerBaseJob

ContainerBrokerBaseJob::JOB_METRIC

Instance Method Summary collapse

Methods inherited from ContainerBrokerBaseJob

request_id_from_args

Instance Method Details

#any_task_referencing_tag?(task_tag) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'app/jobs/remove_unused_tags_job.rb', line 22

def any_task_referencing_tag?(task_tag)
  Task.where(tag_expression(task_tag).exists => true).exists?
end

#perform(*_args) ⇒ Object



6
7
8
# File 'app/jobs/remove_unused_tags_job.rb', line 6

def perform(*_args)
  remove_unreferenced_tags
end

#remove_unreferenced_tagsObject



10
11
12
13
14
15
16
# File 'app/jobs/remove_unused_tags_job.rb', line 10

def remove_unreferenced_tags
  TaskTag
    .all
    .to_a
    .reject { |task_tag| any_task_referencing_tag?(task_tag) }
    .each(&:destroy!)
end

#tag_expression(task_tag) ⇒ Object



18
19
20
# File 'app/jobs/remove_unused_tags_job.rb', line 18

def tag_expression(task_tag)
  :"tags.#{task_tag.name}"
end