diff --git a/app/logical/storage_manager.rb b/app/logical/storage_manager.rb index 2937d6b3c..121887a0e 100644 --- a/app/logical/storage_manager.rb +++ b/app/logical/storage_manager.rb @@ -115,7 +115,7 @@ class StorageManager def seo_tags(post) return "" if !tagged_filenames - tags = post.humanized_essential_tag_string.gsub(/[^a-z0-9]+/, "_").gsub(/(?:^_+)|(?:_+$)/, "").gsub(/_{2,}/, "_") + tags = post.presenter.humanized_essential_tag_string.gsub(/[^a-z0-9]+/, "_").gsub(/(?:^_+)|(?:_+$)/, "").gsub(/_{2,}/, "_") "__#{tags}__" end end diff --git a/app/models/post.rb b/app/models/post.rb index 93944b4a9..477380a4f 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -36,7 +36,6 @@ class Post < ApplicationRecord after_save :create_version after_save :update_parent_on_save after_save :apply_post_metatags - after_save :expire_essential_tag_string_cache after_commit :delete_files, :on => :destroy after_commit :remove_iqdb_async, :on => :destroy after_commit :update_iqdb_async, :on => :create @@ -936,36 +935,6 @@ class Post < ApplicationRecord end end - def expire_essential_tag_string_cache - Cache.delete("hets-#{id}") - end - - def humanized_essential_tag_string - @humanized_essential_tag_string ||= Cache.get("hets-#{id}", 1.hour.to_i) do - string = [] - - TagCategory.humanized_list.each do |category| - typetags = typed_tags(category) - TagCategory.humanized_mapping[category]["exclusion"] - if TagCategory.humanized_mapping[category]["slice"] > 0 - typetags = typetags.slice(0,TagCategory.humanized_mapping[category]["slice"]) + (typetags.length > TagCategory.humanized_mapping[category]["slice"] ? ["others"] : []) - end - if TagCategory.humanized_mapping[category]["regexmap"] != // - typetags = typetags.map do |tag| - tag.match(TagCategory.humanized_mapping[category]["regexmap"])[1] - end - end - if typetags.any? - if category != "copyright" || typed_tags("character").any? - string << TagCategory.humanized_mapping[category]["formatstr"] % typetags.to_sentence - else - string << typetags.to_sentence - end - end - end - string.empty? ? "##{id}" : string.join(" ").tr("_", " ") - end - end - TagCategory.categories.each do |category| define_method("tag_string_#{category}") do typed_tags(category).join(" ") diff --git a/app/presenters/post_presenter.rb b/app/presenters/post_presenter.rb index e38e24690..f58fa782d 100644 --- a/app/presenters/post_presenter.rb +++ b/app/presenters/post_presenter.rb @@ -144,7 +144,7 @@ class PostPresenter < Presenter end def humanized_essential_tag_string - @post.humanized_essential_tag_string + @humanized_essential_tag_string ||= tag_set_presenter.humanized_essential_tag_string(default: "##{@post.id}") end def filename_for_download diff --git a/app/presenters/tag_set_presenter.rb b/app/presenters/tag_set_presenter.rb index aaa83655c..42432d778 100644 --- a/app/presenters/tag_set_presenter.rb +++ b/app/presenters/tag_set_presenter.rb @@ -61,6 +61,36 @@ class TagSetPresenter < Presenter end.join(" \n") end + def humanized_essential_tag_string(category_list: TagCategory.humanized_list, default: "") + strings = category_list.map do |category| + mapping = TagCategory.humanized_mapping[category] + max_tags = mapping["slice"] + regexmap = mapping["regexmap"] + formatstr = mapping["formatstr"] + excluded_tags = mapping["exclusion"] + + type_tags = tags_for_category(category).map(&:name) - excluded_tags + next if type_tags.empty? + + if max_tags > 0 && type_tags.length > max_tags + type_tags = type_tags.take(max_tags) + ["others"] + end + + if regexmap != // + type_tags = type_tags.map { |tag| tag.match(regexmap)[1] } + end + + if category == "copyright" && tags_for_category("character").blank? + type_tags.to_sentence + else + formatstr % type_tags.to_sentence + end + end + + strings = strings.compact.join(" ").tr("_", " ") + strings.blank? ? default : strings + end + private def tags @@ -128,5 +158,5 @@ class TagSetPresenter < Presenter html end - memoize :tags, :tags_by_category, :ordered_tags + memoize :tags, :tags_by_category, :ordered_tags, :humanized_essential_tag_string end diff --git a/app/views/comments/index.atom.builder b/app/views/comments/index.atom.builder index 19e1c8b75..14508448b 100644 --- a/app/views/comments/index.atom.builder +++ b/app/views/comments/index.atom.builder @@ -9,7 +9,7 @@ atom_feed(root_url: comments_url(host: Danbooru.config.hostname)) do |feed| @comments.each do |comment| feed.entry(comment, published: comment.created_at, updated: comment.updated_at) do |entry| - entry.title("@#{comment.creator_name} on post ##{comment.post_id} (#{comment.post.humanized_essential_tag_string})") + entry.title("@#{comment.creator_name} on post ##{comment.post_id} (#{comment.post.presenter.humanized_essential_tag_string})") entry.content(<<-EOS.strip_heredoc, type: "html")