summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2015-05-25 12:09:01 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2015-05-25 12:09:01 +0000
commit5e28f0b1b6aaabb327d458213f14cf6e5b90ae8a (patch)
tree4741dd774a6928a2b82d695fe3747f1a5f557993 /app
parent31bffaa053fc4f3d96224a4d93b465d4eab92395 (diff)
downloadredmine-5e28f0b1b6aaabb327d458213f14cf6e5b90ae8a.tar.gz
redmine-5e28f0b1b6aaabb327d458213f14cf6e5b90ae8a.zip
Code cleanup.
git-svn-id: http://svn.redmine.org/redmine/trunk@14274 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-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