jobs: migrate related tag updates to ActiveJob.
This commit is contained in:
7
app/jobs/update_related_tags_job.rb
Normal file
7
app/jobs/update_related_tags_job.rb
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
class UpdateRelatedTagsJob < ApplicationJob
|
||||||
|
queue_as :default
|
||||||
|
|
||||||
|
def perform(tag)
|
||||||
|
tag.update_related
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -872,7 +872,7 @@ class Tag < ApplicationRecord
|
|||||||
|
|
||||||
if Cache.get("urt:#{key}").nil? && should_update_related?
|
if Cache.get("urt:#{key}").nil? && should_update_related?
|
||||||
if post_count < COSINE_SIMILARITY_RELATED_TAG_THRESHOLD
|
if post_count < COSINE_SIMILARITY_RELATED_TAG_THRESHOLD
|
||||||
delay(:queue => "default").update_related
|
UpdateRelatedTagsJob.perform_later(self)
|
||||||
else
|
else
|
||||||
sqs = SqsService.new(Danbooru.config.aws_sqs_reltagcalc_url)
|
sqs = SqsService.new(Danbooru.config.aws_sqs_reltagcalc_url)
|
||||||
sqs.send_message("calculate #{name}")
|
sqs.send_message("calculate #{name}")
|
||||||
|
|||||||
@@ -283,4 +283,15 @@ class TagTest < ActiveSupport::TestCase
|
|||||||
assert_equal(1, tag.reload.post_count)
|
assert_equal(1, tag.reload.post_count)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "The #related_tag_array method" do
|
||||||
|
should "update the related tags" do
|
||||||
|
create(:post, tag_string: "bkub")
|
||||||
|
tag = Tag.find_by_name("bkub")
|
||||||
|
|
||||||
|
assert_nil(tag.related_tags)
|
||||||
|
perform_enqueued_jobs { tag.related_tag_array }
|
||||||
|
assert_equal([["bkub", "1"]], tag.reload.related_tag_array)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user