From d26c52c2fa65170a52dcc524ab5d27b3a53999dc Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 14 Apr 2021 12:00:59 +0200 Subject: [PATCH] Memoize OrderBalance instance There's no need to create an instance of such class for every call to one of its methods. The balance is computed each time anyway, so it'll always be up-to-date. --- app/models/concerns/balance.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/concerns/balance.rb b/app/models/concerns/balance.rb index 651a439417..af70eacce5 100644 --- a/app/models/concerns/balance.rb +++ b/app/models/concerns/balance.rb @@ -9,7 +9,7 @@ module Balance # Branches by the OrderBalance abstraction def outstanding_balance - OrderBalance.new(self) + @order_balance ||= OrderBalance.new(self) end # Returns the order balance by considering the total as money owed to the order distributor aka.