diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2015-08-31 03:38:34 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2015-08-31 03:38:34 +0000 |
commit | 8e84df24ea251bcef74a8ce1f22a84f97db66f68 (patch) | |
tree | 630b0348c8b68fa7b899620eac6c27b468e75155 | |
parent | 925db0c28fcb7d4e5eae3af3861bfbc1c0d5d7c2 (diff) | |
download | redmine-8e84df24ea251bcef74a8ce1f22a84f97db66f68.tar.gz redmine-8e84df24ea251bcef74a8ce1f22a84f97db66f68.zip |
Merged r14408 from trunk to 3.1-stable (#11253, #20456)
Limit queries to given issues only.
git-svn-id: http://svn.redmine.org/redmine/branches/3.1-stable@14535 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/models/issue.rb | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb index 5c9f81efa..72df50cd6 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -950,7 +950,7 @@ class Issue < ActiveRecord::Base # Preloads visible total spent time for a collection of issues def self.load_visible_spent_hours(issues, user=User.current) if issues.any? - hours_by_issue_id = TimeEntry.visible(user).group(:issue_id).sum(:hours) + hours_by_issue_id = TimeEntry.visible(user).where(:issue_id => issues.map(&:id)).group(:issue_id).sum(:hours) issues.each do |issue| issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0) end @@ -959,8 +959,10 @@ class Issue < ActiveRecord::Base def self.load_visible_total_spent_hours(issues, user=User.current) if issues.any? - hours_by_issue_id = TimeEntry.visible(user).joins(:issue).joins("JOIN #{Issue.table_name} parent ON parent.root_id = #{Issue.table_name}.root_id" + - " AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt").group("parent.id").sum(:hours) + hours_by_issue_id = TimeEntry.visible(user).joins(:issue). + joins("JOIN #{Issue.table_name} parent ON parent.root_id = #{Issue.table_name}.root_id" + + " AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt"). + where("parent.id IN (?)", issues.map(&:id)).group("parent.id").sum(:hours) issues.each do |issue| issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0) end |