Patch #40000
closedOptimize gantt chart rendering for issues without subtasks
Description
This patch introduces an optimization to the gantt chart rendering process. We can improve the performance by avoiding unnecessary database queries for issues that do not have subtasks, especially when rendering gantt with large numbers of issues.
The current implementation in the Gantt chart helper performs a database query to fetch children for every issue, regardless of whether the issue has subtasks.
Issue Load (0.4ms) SELECT "issues".* FROM "issues" WHERE "issues"."parent_id" = $1 ORDER BY "issues"."lft" ASC [["parent_id", 1]] ↳ lib/redmine/helpers/gantt.rb:768:in `html_subject' Issue Load (0.3ms) SELECT "issues".* FROM "issues" WHERE "issues"."parent_id" = $1 ORDER BY "issues"."lft" ASC [["parent_id", 15]] ↳ lib/redmine/helpers/gantt.rb:768:in `html_subject' Issue Load (0.4ms) SELECT "issues".* FROM "issues" WHERE "issues"."parent_id" = $1 ORDER BY "issues"."lft" ASC [["parent_id", 16]] ↳ lib/redmine/helpers/gantt.rb:768:in `html_subject' Issue Load (0.2ms) SELECT "issues".* FROM "issues" WHERE "issues"."parent_id" = $1 ORDER BY "issues"."lft" ASC [["parent_id", 17]] ↳ lib/redmine/helpers/gantt.rb:768:in `html_subject' Issue Load (0.1ms) SELECT "issues".* FROM "issues" WHERE "issues"."parent_id" = $1 ORDER BY "issues"."lft" ASC [["parent_id", 18]]
With the patch applied, it first checks if the issue has children by using object.leaf?
. If the issue has no children, it avoids the database query to retrieve children. This check can reduce a considerable number of SQL queries.
Below is the test result with 500 issues. All issues don't have subtasks.
Without the patch:
$ hey -n 50 -c 1 http://localhost:3000/projects/ecookbook/issues/gantt Summary: Total: 19.2706 secs Slowest: 0.5254 secs Fastest: 0.3520 secs Average: 0.3854 secs Requests/sec: 2.5946 Total data: 61809550 bytes Size/request: 1236191 bytes
With the patch applied:
$ hey -n 50 -c 1 http://localhost:3000/projects/ecookbook/issues/gantt Summary: Total: 13.4183 secs Slowest: 0.2972 secs Fastest: 0.2455 secs Average: 0.2684 secs Requests/sec: 3.7263 Total data: 61809550 bytes Size/request: 1236191 bytes
Files