TagSetPresenter: refactor tag string for post edit form.

Move PostPresenter#categorized_tag_groups to TagSetPresenter#split_tag_list_text.

This allows split_tag_list_text to reuse the same set of tags already
fetched by the tag set presenter for the sidebar.

This avoids a memcache call to get the tag categories when rendering the
tag string for the post edit form.
This commit is contained in:
evazion
2018-09-30 17:46:33 -05:00
parent b1f2096d72
commit 739bb1270c
3 changed files with 24 additions and 21 deletions

View File

@@ -1,6 +1,6 @@
class PostPresenter < Presenter
attr_reader :pool, :next_post_in_pool
delegate :tag_list_html, :split_tag_list_html, :inline_tag_list_html, to: :tag_set_presenter
delegate :tag_list_html, :split_tag_list_html, :split_tag_list_text, :inline_tag_list_html, to: :tag_set_presenter
def self.preview(post, options = {})
if post.nil?
@@ -151,22 +151,6 @@ class PostPresenter < Presenter
"#{humanized_essential_tag_string} - #{@post.md5}.#{@post.file_ext}"
end
def categorized_tag_groups
string = []
TagCategory.categorized_list.each do |category|
if @post.typed_tags(category).any?
string << @post.typed_tags(category).join(" ")
end
end
string
end
def categorized_tag_string
categorized_tag_groups.join(" \n")
end
def safe_mode_message(template)
html = ["This image is unavailable on safe mode (#{Danbooru.config.app_name}). Go to "]
html << template.link_to("Danbooru", "https://danbooru.donmai.us") # XXX don't hardcode.