From 43e8a8a01b6385326d9d01d8b5f0468cf1725770 Mon Sep 17 00:00:00 2001 From: evazion Date: Mon, 12 Aug 2019 13:38:45 -0500 Subject: [PATCH] search: reduce queries in wiki excerpts (#4120). Using `any?` here translated each lookup into two queries, one to check if the aliases/implications existed and one to actually load them. Using `present?` avoids the existence check. --- app/helpers/tags_helper.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/helpers/tags_helper.rb b/app/helpers/tags_helper.rb index e1979f317..21c32d62b 100644 --- a/app/helpers/tags_helper.rb +++ b/app/helpers/tags_helper.rb @@ -10,26 +10,26 @@ module TagsHelper html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_aliases")}).

" end - if tag.consequent_aliases.any? + if tag.consequent_aliases.present? html << "

The following tags are aliased to this tag: " html << raw(tag.consequent_aliases.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", ")) html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_aliases")}).

" end automatic_tags = TagImplication.automatic_tags_for([tag.name]) - if automatic_tags.any? + if automatic_tags.present? html << "

This tag automatically adds " html << raw(automatic_tags.map {|x| link_to(x, show_or_new_wiki_pages_path(:title => x))}.join(", ")) html << " (#{link_to "learn more", wiki_pages_path(title: "help:autotags")}).

" end - if tag.antecedent_implications.any? + if tag.antecedent_implications.present? html << "

This tag implicates " html << raw(tag.antecedent_implications.map {|x| link_to(x.consequent_name, show_or_new_wiki_pages_path(:title => x.consequent_name))}.join(", ")) html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_implications")}).

" end - if tag.consequent_implications.any? + if tag.consequent_implications.present? html << "

The following tags implicate this tag: " html << raw(tag.consequent_implications.map {|x| link_to(x.antecedent_name, show_or_new_wiki_pages_path(:title => x.antecedent_name))}.join(", ")) html << " (#{link_to "learn more", wiki_pages_path(title: "help:tag_implications")}).

"