@@ -950,7 +950,7 class Issue < ActiveRecord::Base | |||||
950 | # Preloads visible total spent time for a collection of issues |
|
950 | # Preloads visible total spent time for a collection of issues | |
951 | def self.load_visible_spent_hours(issues, user=User.current) |
|
951 | def self.load_visible_spent_hours(issues, user=User.current) | |
952 | if issues.any? |
|
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 | issues.each do |issue| |
|
954 | issues.each do |issue| | |
955 | issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0) |
|
955 | issue.instance_variable_set "@spent_hours", (hours_by_issue_id[issue.id] || 0) | |
956 | end |
|
956 | end | |
@@ -959,8 +959,10 class Issue < ActiveRecord::Base | |||||
959 |
|
959 | |||
960 | def self.load_visible_total_spent_hours(issues, user=User.current) |
|
960 | def self.load_visible_total_spent_hours(issues, user=User.current) | |
961 | if issues.any? |
|
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" + |
|
962 | hours_by_issue_id = TimeEntry.visible(user).joins(:issue). | |
963 |
" |
|
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 | issues.each do |issue| |
|
966 | issues.each do |issue| | |
965 | issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0) |
|
967 | issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0) | |
966 | end |
|
968 | end |
General Comments 0
You need to be logged in to leave comments.
Login now