summaryrefslogtreecommitdiffstats
path: root/app/models/issue.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-07-05 12:53:32 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-07-05 12:53:32 +0000
commit67ff5550a60084e6f24ec321dd734bfb69f05703 (patch)
tree7a37feebbe5a79d7ea3bf8342ce70f68eace1678 /app/models/issue.rb
parent5e1a6e1040f2b854b14210c091c22d7327863d48 (diff)
downloadredmine-67ff5550a60084e6f24ec321dd734bfb69f05703.tar.gz
redmine-67ff5550a60084e6f24ec321dd734bfb69f05703.zip
Limit queries to given issues only.
git-svn-id: http://svn.redmine.org/redmine/trunk@14408 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/issue.rb')
-rw-r--r--app/models/issue.rb8
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