Skip to content

Commit

Permalink
Create all tags in one background job
Browse files Browse the repository at this point in the history
Each tag in a separate background job run means background job overhead
for a small task, and it can also lead to inconsistencies
  • Loading branch information
vasconsaurus committed Sep 2, 2024
1 parent 158e8f6 commit a1bde47
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/models/concerns/project_media_creators.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ def create_claim_description_and_fact_check
end

def create_tags
self.set_tags.each { |tag| GenericWorker.perform_in(1.second, 'Tag', 'create!', annotated_type: 'ProjectMedia' , annotated_id: self.id, tag: tag.strip, skip_check_ability: true) } if self.set_tags.is_a?(Array)
if self.set_tags.is_a?(Array)
GenericWorker.perform_in(1.second, 'ProjectMedia', 'create_tags_in_background', project_media_id: self.id, tags_json: self.set_tags.to_json)
end
end
end
7 changes: 7 additions & 0 deletions app/models/project_media.rb
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,13 @@ def add_nested_objects(ms)
ms.attributes[:requests] = requests
end


def self.create_tags_in_background(**params)
project_media = ProjectMedia.find(params['project_media_id'])
tags = JSON.parse(params['tags_json'])
tags.each { |tag| Tag.create! annotated: project_media, tag: tag.strip, skip_check_ability: true }
end

# private
#
# Please add private methods to app/models/concerns/project_media_private.rb
Expand Down

0 comments on commit a1bde47

Please sign in to comment.