mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-04 19:53:44 +00:00
Fix performance issues in budget controller.
This commit is contained in:
@@ -46,11 +46,8 @@ use Illuminate\View\View;
|
|||||||
class ShowController extends Controller
|
class ShowController extends Controller
|
||||||
{
|
{
|
||||||
use PeriodOverview, AugumentData;
|
use PeriodOverview, AugumentData;
|
||||||
/** @var JournalRepositoryInterface */
|
private JournalRepositoryInterface $journalRepos;
|
||||||
private $journalRepos;
|
private BudgetRepositoryInterface $repository;
|
||||||
|
|
||||||
/** @var BudgetRepositoryInterface */
|
|
||||||
private $repository;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ShowController constructor.
|
* ShowController constructor.
|
||||||
|
@@ -199,6 +199,7 @@ trait AugumentData
|
|||||||
/** @var BudgetLimitRepositoryInterface $blRepository */
|
/** @var BudgetLimitRepositoryInterface $blRepository */
|
||||||
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
$blRepository = app(BudgetLimitRepositoryInterface::class);
|
||||||
|
|
||||||
|
|
||||||
// properties for cache
|
// properties for cache
|
||||||
$cache = new CacheProperties;
|
$cache = new CacheProperties;
|
||||||
$cache->addProperty($start);
|
$cache->addProperty($start);
|
||||||
@@ -207,18 +208,19 @@ trait AugumentData
|
|||||||
$cache->addProperty('get-limits');
|
$cache->addProperty('get-limits');
|
||||||
|
|
||||||
if ($cache->has()) {
|
if ($cache->has()) {
|
||||||
return $cache->get(); // @codeCoverageIgnore
|
return $cache->get(); // @codeCoverageIgnore
|
||||||
}
|
}
|
||||||
|
|
||||||
$set = $blRepository->getBudgetLimits($budget, $start, $end);
|
$set = $blRepository->getBudgetLimits($budget, $start, $end);
|
||||||
$limits = new Collection();
|
$limits = new Collection();
|
||||||
$budgetCollection = new Collection([$budget]);
|
$budgetCollection = new Collection([$budget]);
|
||||||
|
|
||||||
/** @var BudgetLimit $entry */
|
/** @var BudgetLimit $entry */
|
||||||
foreach ($set as $entry) {
|
foreach ($set as $entry) {
|
||||||
$currency = $entry->transactionCurrency;
|
$currency = $entry->transactionCurrency;
|
||||||
// clone because these objects change each other.
|
// clone because these objects change each other.
|
||||||
$currentStart = clone $start;
|
$currentStart = clone $entry->start_date;
|
||||||
$currentEnd = clone $end;
|
$currentEnd = clone $entry->end_date;
|
||||||
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency);
|
$expenses = $opsRepository->sumExpenses($currentStart, $currentEnd, null, $budgetCollection, $currency);
|
||||||
$spent = $expenses[(int)$currency->id]['sum'] ?? '0';
|
$spent = $expenses[(int)$currency->id]['sum'] ?? '0';
|
||||||
$entry->spent = $spent;
|
$entry->spent = $spent;
|
||||||
|
Reference in New Issue
Block a user