From 6cbf56322b4691ec1da7c543b336ec9ca9a715f4 Mon Sep 17 00:00:00 2001 From: r888888888 Date: Mon, 4 Jan 2016 11:46:49 -0800 Subject: [PATCH] for high post count tags use cosine similarity to calculate related tags --- app/models/tag.rb | 10 ++++++++-- config/danbooru_default_config.rb | 3 +++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/models/tag.rb b/app/models/tag.rb index ff946eae0..db2530ac2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -1,4 +1,5 @@ class Tag < ActiveRecord::Base + COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 100_000 METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|sub|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|gentags|arttags|chartags|copytags|parent|-parent|child|pixiv_id|pixiv|search" SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm" attr_accessible :category, :as => [:moderator, :janitor, :gold, :member, :anonymous, :default, :builder, :admin] @@ -621,8 +622,13 @@ class Tag < ActiveRecord::Base end def update_related_if_outdated - if should_update_related? && Delayed::Job.count < 200 - delay(:queue => "default").update_related + if should_update_related? + 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_queue_reltagcalc_url) + sqs.send_message("calculate #{name}") + end end end diff --git a/config/danbooru_default_config.rb b/config/danbooru_default_config.rb index 54f20146b..d7ee80497 100644 --- a/config/danbooru_default_config.rb +++ b/config/danbooru_default_config.rb @@ -431,6 +431,9 @@ module Danbooru def aws_sqs_queue_url end + def aws_sqs_queue_reltagcalc_url + end + def aws_sqs_region end end