From 1631b422f1f077dc86d0ece4a860de6bde92965b Mon Sep 17 00:00:00 2001 From: James Cole Date: Tue, 31 Dec 2024 08:17:35 +0100 Subject: [PATCH] Clean up logs, add cache. --- .../Internal/Support/CreditRecalculateService.php | 6 +++--- app/Support/Steam.php | 9 +++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Services/Internal/Support/CreditRecalculateService.php b/app/Services/Internal/Support/CreditRecalculateService.php index 468b3f4299..aab5f0fb6d 100644 --- a/app/Services/Internal/Support/CreditRecalculateService.php +++ b/app/Services/Internal/Support/CreditRecalculateService.php @@ -159,7 +159,7 @@ class CreditRecalculateService private function processWorkAccount(Account $account): void { - Log::debug(sprintf('Now processing account #%d ("%s"). All amounts with 2 decimals!', $account->id, $account->name)); + Log::debug(sprintf('Now processing account #%d ("%s").', $account->id, $account->name)); // get opening balance (if present) $this->repository->setUser($account->user); $direction = (string) $this->repository->getMetaValue($account, 'liability_direction'); @@ -230,7 +230,7 @@ class CreditRecalculateService return; } - Log::debug('Opening balance is valid'); + //Log::debug('Opening balance is valid'); } /** @@ -263,7 +263,7 @@ class CreditRecalculateService return $leftOfDebt; } if (TransactionTypeEnum::LIABILITY_CREDIT->value === $type || TransactionTypeEnum::OPENING_BALANCE->value === $type) { - Log::warning(sprintf('Transaction type is "%s", so do nothing.', $type)); + // Log::warning(sprintf('Transaction type is "%s", so do nothing.', $type)); return $leftOfDebt; } diff --git a/app/Support/Steam.php b/app/Support/Steam.php index de646bdf74..73cf062407 100644 --- a/app/Support/Steam.php +++ b/app/Support/Steam.php @@ -310,7 +310,15 @@ class Steam */ public function finalAccountBalance(Account $account, Carbon $date): array { + $cache = new CacheProperties(); + $cache->addProperty($account->id); + $cache->addProperty($date); + if ($cache->has()) { + return $cache->get(); + } + Log::debug(sprintf('Now in finalAccountBalance(#%d, "%s", "%s")', $account->id, $account->name, $date->format('Y-m-d H:i:s'))); + $native = Amount::getDefaultCurrencyByUserGroup($account->user->userGroup); $convertToNative = Amount::convertToNative($account->user); $accountCurrency = $this->getAccountCurrency($account); @@ -387,6 +395,7 @@ class Steam } $final = array_merge($return, $others); // Log::debug('Return is', $final); + $cache->store($final); return $final; }