Optimize Gantt chart rendering by reducing version-related queries (#42663).

Patch by Go MAEDA (user:maeda).


git-svn-id: https://svn.redmine.org/redmine/trunk@23750 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2025-05-07 06:54:08 +00:00
parent 3c0faad370
commit b408b59d99

View File

@@ -198,12 +198,18 @@ module Redmine
# Returns the distinct versions of the issues that belong to +project+ # Returns the distinct versions of the issues that belong to +project+
def project_versions(project) def project_versions(project)
project_issues(project).filter_map(&:fixed_version).uniq @project_versions ||= {}
@project_versions[project&.id] ||= begin
ids = project_issues(project).filter_map(&:fixed_version_id).uniq
Version.where(id: ids).to_a
end
end end
# Returns the issues that belong to +project+ and are assigned to +version+ # Returns the issues that belong to +project+ and are assigned to +version+
def version_issues(project, version) def version_issues(project, version)
project_issues(project).select {|issue| issue.fixed_version == version} @version_issues ||= {}
@version_issues[[project&.id, version&.id]] ||=
project_issues(project).select {|issue| issue.fixed_version_id == version&.id}
end end
def render(options={}) def render(options={})
@@ -232,7 +238,7 @@ module Redmine
render_object_row(project, options) render_object_row(project, options)
increment_indent(options) do increment_indent(options) do
# render issue that are not assigned to a version # render issue that are not assigned to a version
issues = project_issues(project).select {|i| i.fixed_version.nil?} issues = project_issues(project).select {|i| i.fixed_version_id.nil?}
render_issues(issues, options) render_issues(issues, options)
# then render project versions and their issues # then render project versions and their issues
versions = project_versions(project) versions = project_versions(project)
@@ -778,10 +784,14 @@ module Redmine
tag_options[:id] = "issue-#{object.id}" tag_options[:id] = "issue-#{object.id}"
tag_options[:class] = "issue-subject hascontextmenu" tag_options[:class] = "issue-subject hascontextmenu"
tag_options[:title] = object.subject tag_options[:title] = object.subject
children = object.leaf? ? [] : object.children & project_issues(object.project)
has_children = has_children =
children.present? && if object.leaf?
children.collect(&:fixed_version).uniq.intersect?([object.fixed_version]) false
else
children = object.children & project_issues(object.project)
fixed_version_id = object.fixed_version_id
children.any? {|child| child.fixed_version_id == fixed_version_id}
end
when Version when Version
tag_options[:id] = "version-#{object.id}" tag_options[:id] = "version-#{object.id}"
tag_options[:class] = "version-name" tag_options[:class] = "version-name"