[#4646] Memoize some calculated values in the Contract
This commit is contained in:
1 parent
691adf521e
commit
bf270623d2
1 file changed
+15
@@ -1,5 +1,6 @@
|
|||||||
class Contract < ActiveRecord::Base
|
class Contract < ActiveRecord::Base
|
||||||
unloadable
|
unloadable
|
||||||
|
extend ActiveSupport::Memoizable
|
||||||
|
|
||||||
ViewPrecision = 0
|
ViewPrecision = 0
|
||||||
|
|
||||||
@@ -45,74 +46,88 @@ class Contract < ActiveRecord::Base
|
|||||||
def labor_budget
|
def labor_budget
|
||||||
summarize_associated_values(deliverables, :labor_budget_total)
|
summarize_associated_values(deliverables, :labor_budget_total)
|
||||||
end
|
end
|
||||||
|
memoize :labor_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
# OPTIMIZE: also hits redmine_overhead which is known to be slow
|
# OPTIMIZE: also hits redmine_overhead which is known to be slow
|
||||||
def labor_spent
|
def labor_spent
|
||||||
summarize_associated_values(deliverables, :labor_budget_spent)
|
summarize_associated_values(deliverables, :labor_budget_spent)
|
||||||
end
|
end
|
||||||
|
memoize :labor_spent
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def overhead_budget
|
def overhead_budget
|
||||||
summarize_associated_values(deliverables, :overhead_budget_total)
|
summarize_associated_values(deliverables, :overhead_budget_total)
|
||||||
end
|
end
|
||||||
|
memoize :overhead_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
# OPTIMIZE: also hits redmine_overhead which is known to be slow
|
# OPTIMIZE: also hits redmine_overhead which is known to be slow
|
||||||
def overhead_spent
|
def overhead_spent
|
||||||
summarize_associated_values(deliverables, :overhead_spent)
|
summarize_associated_values(deliverables, :overhead_spent)
|
||||||
end
|
end
|
||||||
|
memoize :overhead_spent
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def estimated_hour_budget
|
def estimated_hour_budget
|
||||||
summarize_associated_values(deliverables, :estimated_hour_budget_total)
|
summarize_associated_values(deliverables, :estimated_hour_budget_total)
|
||||||
end
|
end
|
||||||
|
memoize :estimated_hour_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def estimated_hour_spent
|
def estimated_hour_spent
|
||||||
summarize_associated_values(deliverables, :hours_spent_total)
|
summarize_associated_values(deliverables, :hours_spent_total)
|
||||||
end
|
end
|
||||||
|
memoize :estimated_hour_spent
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def total_budget
|
def total_budget
|
||||||
summarize_associated_values(deliverables, :total)
|
summarize_associated_values(deliverables, :total)
|
||||||
end
|
end
|
||||||
|
memoize :total_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def total_spent
|
def total_spent
|
||||||
summarize_associated_values(deliverables, :total_spent)
|
summarize_associated_values(deliverables, :total_spent)
|
||||||
end
|
end
|
||||||
|
memoize :total_spent
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def profit_budget
|
def profit_budget
|
||||||
summarize_associated_values(deliverables, :profit_budget)
|
summarize_associated_values(deliverables, :profit_budget)
|
||||||
end
|
end
|
||||||
|
memoize :profit_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def profit_left
|
def profit_left
|
||||||
summarize_associated_values(deliverables, :profit_left)
|
summarize_associated_values(deliverables, :profit_left)
|
||||||
end
|
end
|
||||||
alias_method :profit_spent, :profit_left
|
alias_method :profit_spent, :profit_left
|
||||||
|
memoize :profit_left
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def fixed_budget
|
def fixed_budget
|
||||||
summarize_associated_values(deliverables, :fixed_budget_total)
|
summarize_associated_values(deliverables, :fixed_budget_total)
|
||||||
end
|
end
|
||||||
|
memoize :fixed_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def fixed_spent
|
def fixed_spent
|
||||||
summarize_associated_values(deliverables, :fixed_budget_total_spent)
|
summarize_associated_values(deliverables, :fixed_budget_total_spent)
|
||||||
end
|
end
|
||||||
|
memoize :fixed_spent
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def fixed_markup_budget
|
def fixed_markup_budget
|
||||||
summarize_associated_values(deliverables, :fixed_markup_budget_total)
|
summarize_associated_values(deliverables, :fixed_markup_budget_total)
|
||||||
end
|
end
|
||||||
|
memoize :fixed_markup_budget
|
||||||
|
|
||||||
# OPTIMIZE: N+1
|
# OPTIMIZE: N+1
|
||||||
def fixed_markup_spent
|
def fixed_markup_spent
|
||||||
summarize_associated_values(deliverables, :fixed_markup_budget_total_spent)
|
summarize_associated_values(deliverables, :fixed_markup_budget_total_spent)
|
||||||
end
|
end
|
||||||
|
memoize :fixed_markup_spent
|
||||||
|
|
||||||
def after_initialize
|
def after_initialize
|
||||||
self.executed = false unless self.executed.present?
|
self.executed = false unless self.executed.present?
|
||||||
|
|||||||
Reference in new issue
Block a user