From 21842996d44b34db74e85e721306a1de6ab7afad Mon Sep 17 00:00:00 2001 From: r888888888 Date: Tue, 12 Jan 2016 11:26:39 -0800 Subject: [PATCH] reduce redundant sqs calls for updating related tags --- Gemfile.lock | 3 +++ app/models/tag.rb | 11 +++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 9f360122b..f61479045 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -384,3 +384,6 @@ DEPENDENCIES vcr webmock whenever + +BUNDLED WITH + 1.10.0 diff --git a/app/models/tag.rb b/app/models/tag.rb index 71d811619..25bf747fc 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -626,8 +626,15 @@ class Tag < ActiveRecord::Base if post_count < COSINE_SIMILARITY_RELATED_TAG_THRESHOLD && Delayed::Job.count < 200 delay(:queue => "default").update_related elsif post_count >= COSINE_SIMILARITY_RELATED_TAG_THRESHOLD - sqs = SqsService.new(Danbooru.config.aws_sqs_reltagcalc_url) - sqs.send_message("calculate #{name}") + key = Cache.sanitize(name) + cache_check = Cache.get("urt:#{key}") + + if cache_check + sqs = SqsService.new(Danbooru.config.aws_sqs_reltagcalc_url) + sqs.send_message("calculate #{name}") + else + Cache.put("urt:#{key}", true, 600) + end end end end