summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/issue.rb15
1 files changed, 7 insertions, 8 deletions
diff --git a/app/models/issue.rb b/app/models/issue.rb
index 85c3ff871..928dedc91 100644
--- a/app/models/issue.rb
+++ b/app/models/issue.rb
@@ -206,6 +206,7 @@ class Issue < ActiveRecord::Base
@assignable_versions = nil
@relations = nil
@spent_hours = nil
+ @total_spent_hours = nil
@total_estimated_hours = nil
base_reload(*args)
end
@@ -916,15 +917,13 @@ class Issue < ActiveRecord::Base
end
# Returns the total number of hours spent on this issue and its descendants
- #
- # Example:
- # spent_hours => 0.0
- # spent_hours => 50.2
def total_spent_hours
- @total_spent_hours ||=
- self_and_descendants.
- joins("LEFT JOIN #{TimeEntry.table_name} ON #{TimeEntry.table_name}.issue_id = #{Issue.table_name}.id").
- sum("#{TimeEntry.table_name}.hours").to_f || 0.0
+ if leaf?
+ spent_hours
+ else
+ @total_spent_hours ||=
+ self_and_descendants.joins(:time_entries).sum("#{TimeEntry.table_name}.hours").to_f || 0.0
+ end
end
def total_estimated_hours