diff options
author | Go MAEDA <maeda@farend.jp> | 2025-04-08 01:30:37 +0000 |
---|---|---|
committer | Go MAEDA <maeda@farend.jp> | 2025-04-08 01:30:37 +0000 |
commit | ec73d02347da40f97e533dc851d475a8b328afef (patch) | |
tree | 9e277a81e08a2d7c00aca8799ce9df6b63ebf44f | |
parent | 95ddae6e2c22bd28417f2d433896cdd1580f35e8 (diff) | |
download | redmine-ec73d02347da40f97e533dc851d475a8b328afef.tar.gz redmine-ec73d02347da40f97e533dc851d475a8b328afef.zip |
Fix slow loading of global spent time list in MySQL (#40728).
In MySQL, the query to retrieve the global spent time list is sometimes extremely slow (taking several minutes in some environments) due to an inefficient join order chosen by the query optimizer. This patch adds an optimizer hint to improve the join order and ensure consistent performance.
Patch by Go MAEDA (user:maeda).
git-svn-id: https://svn.redmine.org/redmine/trunk@23609 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/time_entry_query.rb | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb index 41997180b..82b895671 100644 --- a/app/models/time_entry_query.rb +++ b/app/models/time_entry_query.rb @@ -164,12 +164,19 @@ class TimeEntryQuery < Query end def base_scope - TimeEntry.visible. - joins(:project, :user). - includes(:activity). - references(:activity). - left_join_issue. - where(statement) + scope = TimeEntry.visible + .joins(:project, :user) + .includes(:activity) + .references(:activity) + .left_join_issue + .where(statement) + + if Redmine::Database.mysql? && ActiveRecord::Base.connection.supports_optimizer_hints? + # Provides MySQL with a hint to use a better join order and avoid slow response times + scope.optimizer_hints('JOIN_ORDER(time_entries, projects, users)') + else + scope + end end def results_scope(options={}) |