Skip to content

Commit

Permalink
Merge performance improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nanego committed Sep 14, 2023
2 parents 376eb7a + 7ad4d96 commit d9a79d9
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/controllers/issue_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ def update
end

def index
@templates = IssueTemplate.order("custom_form desc, tracker_id desc, usage desc").includes(:issues)
@templates = IssueTemplate.order("custom_form desc, tracker_id desc, usage desc")
.includes(:issues_by_attributes, :template_projects_by_attributes,:tracker_by_attributes)
.select(:id, :template_title, :usage,:tracker_id, :template_enabled, :custom_form, :split_description, :subject)

@allowed_projects = IssueTemplate.allowed_target_projects_by_attributes
end

# Updates the template form when changing the project, status or tracker on template creation/update
Expand Down
8 changes: 8 additions & 0 deletions app/models/issue_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class IssueTemplate < ActiveRecord::Base
has_many :issue_template_projects, dependent: :destroy
has_many :template_projects, through: :issue_template_projects, source: :project

has_many :template_projects_by_attributes, -> { select(:id, :name) }, through: :issue_template_projects, source: :project
has_many :issues_by_attributes, -> { select(:issue_template_id) }, class_name: 'Issue'
belongs_to :tracker_by_attributes, -> { select(:id, :name) }, class_name: 'Tracker', :foreign_key => 'tracker_id'

if Redmine::Plugin.installed?(:redmine_multiprojects_issue)
has_and_belongs_to_many :secondary_projects, class_name: 'Project', join_table: 'multiprojects_issue_templates'
end
Expand Down Expand Up @@ -101,6 +105,10 @@ def allowed_target_projects
Project.active
end

def self.allowed_target_projects_by_attributes
Project.active_by_attributes
end

def disabled_projects
Project.all - Project.includes(:enabled_modules).where("enabled_modules.name" => :issue_templates)
end
Expand Down
9 changes: 4 additions & 5 deletions app/views/issue_templates/_list_template.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
<%= image_tag 'icons8-form-64.png', plugin: 'redmine_templates', style: 'width: 40px;padding: 5px;' if issue_template.split_description? %>
</td>
<td><%= link_to_edition.call h(issue_template.template_title), issue_template.template_title %></td>
<td><%= (link_to_edition.call h(issue_template.tracker.name), issue_template.tracker.name) if issue_template.tracker.present? %></td>
<td><%= (link_to_edition.call h(issue_template.tracker_by_attributes.name), issue_template.tracker_by_attributes.name) if issue_template.tracker_by_attributes.present? %></td>
<td><%= link_to_edition.call h(issue_template.subject), issue_template.subject %></td>
<td class="template_projects">
<div>
<%
template_projects = issue_template.template_projects.all.select('id','name')
allowed_projects = issue_template.allowed_target_projects.select('id','name')
template_projects = issue_template.template_projects_by_attributes.all

visible_projects = (allowed_projects & template_projects).to_a
other_projects = (template_projects - allowed_projects).to_a
Expand Down Expand Up @@ -53,7 +52,7 @@
</td>
<td class="template_column_count"><%= issue_template.issue_template_projects.size %></td>
<td class="template_column_count"><%= issue_template.usage %></td>
<td class="template_column_count"><%= issue_template.issues.size %></td>
<td class="template_column_count"><%= issue_template.issues_by_attributes.size %></td>
<% if Setting["plugin_redmine_templates"]["disable_templates"] %>
<td class="center image_enabled_<%= issue_template.id %>">
<%= render "issue_templates/enable_form", issue_template: issue_template %>
Expand All @@ -65,7 +64,7 @@
<%= link_to l(:button_edit), edit_issue_template_path(id: issue_template.id
#, project_id: project.id
), :class => 'icon icon-edit' %>
<% if User.current.admin || (issue_template.template_projects - User.current.projects).empty? %>
<% if User.current.admin || (issue_template.template_projects_by_attributes - User.current.projects).empty? %>
<%= delete_link issue_template_path(issue_template) %>
<% end %>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/issue_templates/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
</thead>
<tbody>
<% @templates.each do |issue_template| %>
<%= render 'list_template', issue_template: issue_template %>
<%= render 'list_template', issue_template: issue_template, allowed_projects: @allowed_projects %>
<% end %>
<% reset_cycle %>
</tbody>
Expand Down
1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require_dependency 'redmine_templates/helpers/projects_helper_patch'
require_dependency 'redmine_templates/helpers/issues_helper_patch'
require_dependency 'redmine_templates/helpers/application_helper_patch'
require_dependency 'redmine_templates/project_patch'
end

Redmine::Plugin.register :redmine_templates do
Expand Down
7 changes: 7 additions & 0 deletions lib/redmine_templates/project_patch.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require_dependency 'project'

class Project < ActiveRecord::Base
scope :active_by_attributes, (lambda do
select('id, name').where(:status => STATUS_ACTIVE)
end)
end

0 comments on commit d9a79d9

Please sign in to comment.