@@ -918,11 +918,10 class Issue < ActiveRecord::Base | |||
|
918 | 918 | |
|
919 | 919 | # Returns the total number of hours spent on this issue and its descendants |
|
920 | 920 | def total_spent_hours |
|
921 | if leaf? | |
|
921 | @total_spent_hours ||= if leaf? | |
|
922 | 922 | spent_hours |
|
923 | 923 | else |
|
924 | @total_spent_hours ||= | |
|
925 | self_and_descendants.joins(:time_entries).sum("#{TimeEntry.table_name}.hours").to_f || 0.0 | |
|
924 | self_and_descendants.joins(:time_entries).sum("#{TimeEntry.table_name}.hours").to_f || 0.0 | |
|
926 | 925 | end |
|
927 | 926 | end |
|
928 | 927 | |
@@ -948,7 +947,7 class Issue < ActiveRecord::Base | |||
|
948 | 947 | end |
|
949 | 948 | end |
|
950 | 949 | |
|
951 | # Preloads visible spent time for a collection of issues | |
|
950 | # Preloads visible total spent time for a collection of issues | |
|
952 | 951 | def self.load_visible_spent_hours(issues, user=User.current) |
|
953 | 952 | if issues.any? |
|
954 | 953 | hours_by_issue_id = TimeEntry.visible(user).group(:issue_id).sum(:hours) |
@@ -958,6 +957,16 class Issue < ActiveRecord::Base | |||
|
958 | 957 | end |
|
959 | 958 | end |
|
960 | 959 | |
|
960 | def self.load_visible_total_spent_hours(issues, user=User.current) | |
|
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 | " AND parent.lft <= #{Issue.table_name}.lft AND parent.rgt >= #{Issue.table_name}.rgt").group("parent.id").sum(:hours) | |
|
964 | issues.each do |issue| | |
|
965 | issue.instance_variable_set "@total_spent_hours", (hours_by_issue_id[issue.id] || 0) | |
|
966 | end | |
|
967 | end | |
|
968 | end | |
|
969 | ||
|
961 | 970 | # Preloads visible relations for a collection of issues |
|
962 | 971 | def self.load_visible_relations(issues, user=User.current) |
|
963 | 972 | if issues.any? |
@@ -353,6 +353,9 class IssueQuery < Query | |||
|
353 | 353 | if has_column?(:spent_hours) |
|
354 | 354 | Issue.load_visible_spent_hours(issues) |
|
355 | 355 | end |
|
356 | if has_column?(:total_spent_hours) | |
|
357 | Issue.load_visible_total_spent_hours(issues) | |
|
358 | end | |
|
356 | 359 | if has_column?(:relations) |
|
357 | 360 | Issue.load_visible_relations(issues) |
|
358 | 361 | end |
General Comments 0
You need to be logged in to leave comments.
Login now