@@ -950,7 +950,7 class Issue < ActiveRecord::Base | |||
|
950 | 950 | # Preloads visible total spent time for a collection of issues |
|
951 | 951 | def self.load_visible_spent_hours(issues, user=User.current) |
|
952 | 952 | if issues.any? |
|
953 | hours_by_issue_id = TimeEntry.visible(user).group(:issue_id).sum(:hours) | |
|
953 | hours_by_issue_id = TimeEntry.visible(user).where(:issue_id => issues.map(&:id)).group(:issue_id).sum(:hours) | |
|
954 | 954 | issues.each do |issue| |
|
955 | 955 | issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0) |
|
956 | 956 | end |
@@ -959,8 +959,10 class Issue < ActiveRecord::Base | |||
|
959 | 959 | |
|
960 | 960 | def self.load_visible_total_spent_hours(issues, user=User.current) |
|
961 | 961 | if issues.any? |
|
962 | hours_by_issue_id = TimeEntry.visible(user).joins(:issue).joins("JOIN #{Issue.table_name} parent ON parent.root_id = #{Issue.table_name}.root_id" + | |
|
963 |
" |
|
|
962 | hours_by_issue_id = TimeEntry.visible(user).joins(:issue). | |
|
963 | joins("JOIN #{Issue.table_name} parent ON parent.root_id = #{Issue.table_name}.root_id" + | |
|
964 | " AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt"). | |
|
965 | where("parent.id IN (?)", issues.map(&:id)).group("parent.id").sum(:hours) | |
|
964 | 966 | issues.each do |issue| |
|
965 | 967 | issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0) |
|
966 | 968 | end |
General Comments 0
You need to be logged in to leave comments.
Login now