From 15a0fd604bc58c1da1f3d028160bf4bac28734bf Mon Sep 17 00:00:00 2001 From: evazion Date: Wed, 13 Apr 2022 03:02:44 -0500 Subject: [PATCH] tags: exclude deprecated tags from related tags list. Don't show deprecated tags in the related tags or translated tags lists when editing a post. It doesn't make sense to recommended adding tags that can't be added to the post. --- app/logical/related_tag_calculator.rb | 2 +- app/logical/source/extractor.rb | 2 +- app/models/tag.rb | 2 ++ app/models/wiki_page.rb | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/logical/related_tag_calculator.rb b/app/logical/related_tag_calculator.rb index fff7bd5d3..b143a3c89 100644 --- a/app/logical/related_tag_calculator.rb +++ b/app/logical/related_tag_calculator.rb @@ -59,7 +59,7 @@ module RelatedTagCalculator tags = Tag.from(tag_counts).joins("JOIN tags ON tags.name = tag") tags = tags.select("tags.*, overlap_count") - tags = tags.where("tags.post_count > 0") + tags = tags.nonempty.undeprecated tags = tags.where(category: category) if category.present? tags = tags.order("overlap_count DESC, tags.post_count DESC, tags.name") tags diff --git a/app/logical/source/extractor.rb b/app/logical/source/extractor.rb index 0ae192984..fec50f6f0 100644 --- a/app/logical/source/extractor.rb +++ b/app/logical/source/extractor.rb @@ -227,7 +227,7 @@ module Source def translated_tags translated_tags = normalized_tags.flat_map(&method(:translate_tag)).uniq.sort - translated_tags.reject(&:artist?) + translated_tags.reject(&:artist?).reject(&:is_deprecated?) end # Given a tag from the source site, should return an array of corresponding Danbooru tags. diff --git a/app/models/tag.rb b/app/models/tag.rb index 3114ffbaa..373d69e45 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -22,6 +22,8 @@ class Tag < ApplicationRecord scope :empty, -> { where("tags.post_count <= 0") } scope :nonempty, -> { where("tags.post_count > 0") } + scope :deprecated, -> { where(is_deprecated: true) } + scope :undeprecated, -> { where(is_deprecated: false) } module ApiMethods def to_legacy_json diff --git a/app/models/wiki_page.rb b/app/models/wiki_page.rb index aa491e9a6..58b19eb65 100644 --- a/app/models/wiki_page.rb +++ b/app/models/wiki_page.rb @@ -206,7 +206,7 @@ class WikiPage < ApplicationRecord def tags titles = DText.parse_wiki_titles(body).uniq - tags = Tag.nonempty.where(name: titles).pluck(:name) + tags = Tag.nonempty.undeprecated.where(name: titles).pluck(:name) tags += TagAlias.active.where(antecedent_name: titles).pluck(:antecedent_name) TagAlias.to_aliased(titles & tags) end