From 4878bcf9cd3dc20bc1282a0883110b8be76a364a Mon Sep 17 00:00:00 2001 From: Vincent Date: Tue, 29 Oct 2024 14:34:36 +0100 Subject: [PATCH] Avoid db queries in reused partials --- app/views/issue_comments/_new_form.html.erb | 1 - app/views/issue_comments/_visibility_form_fields.html.erb | 3 ++- app/views/issue_comments/_visibility_role.html.erb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/issue_comments/_new_form.html.erb b/app/views/issue_comments/_new_form.html.erb index 4c07890..f0d75c3 100644 --- a/app/views/issue_comments/_new_form.html.erb +++ b/app/views/issue_comments/_new_form.html.erb @@ -6,7 +6,6 @@ <%= error_messages_for 'issue' %>
- <%= render "issue_comments/visibility_form_fields" %> <%= f.text_area :notes, :cols => 60, :rows => 10, :class => 'wiki-edit', :no_label => true, :id => 'issue_comment' %> diff --git a/app/views/issue_comments/_visibility_form_fields.html.erb b/app/views/issue_comments/_visibility_form_fields.html.erb index 9e3be0a..90ae7e2 100644 --- a/app/views/issue_comments/_visibility_form_fields.html.erb +++ b/app/views/issue_comments/_visibility_form_fields.html.erb @@ -8,8 +8,9 @@ <% disabled = "disabled" if involved.present? && @checked_roles.size == 1 %> <% css_classes = "#{involved} #{disabled} " %> <% if Redmine::Plugin.installed?(:redmine_limited_visibility) %> + <% @users_by_function ||= @project.users_by_function if @project.present? %> <%= render "issue_comments/visibility_role", :function => role, styles: css_classes %> <% end %> <% end %>
-<%= hidden_field_tag "journal[visibility]", @checked_roles.map(&:id).join('|'), id: "journal_visibility", data: { id: @journal.present? ? @journal.id : 0 } %> +<%= hidden_field_tag "journal[visibility]", @checked_roles.map(&:id).join('|'), id: "journal_visibility", data: { id: @journal.present? ? @journal.id : 0 } %> diff --git a/app/views/issue_comments/_visibility_role.html.erb b/app/views/issue_comments/_visibility_role.html.erb index 68a02ee..de7a3b3 100644 --- a/app/views/issue_comments/_visibility_role.html.erb +++ b/app/views/issue_comments/_visibility_role.html.erb @@ -1,5 +1,5 @@ -<% if @project.present? - users_by_function = function.users_by_project(@project) +<% if @project.present? && @users_by_function.present? + users_by_function = @users_by_function[function] users_names = users_by_function.blank? ? "Aucun membre n'a ce rĂ´le dans ce projet" : users_by_function.map(&:name).join(", ") end %>