diff --git a/app/Support/Http/Controllers/PeriodOverview.php b/app/Support/Http/Controllers/PeriodOverview.php index 1fae6214dd..5218dc8e38 100644 --- a/app/Support/Http/Controllers/PeriodOverview.php +++ b/app/Support/Http/Controllers/PeriodOverview.php @@ -70,7 +70,7 @@ trait PeriodOverview protected JournalRepositoryInterface $journalRepos; /** - * This method returns "period entries", so nov-2015, dec-2015, etc etc (this depends on the users session range) + * This method returns "period entries", so nov-2015, dec-2015, etc. (this depends on the users session range) * and for each period, the amount of money spent and earned. This is a complex operation which is cached for * performance reasons. * @@ -97,18 +97,26 @@ trait PeriodOverview /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); $entries = []; + $spent= []; + $earned = []; + $transferredAway = []; + $transferredIn = []; // run a custom query because doing this with the collector is MEGA slow. $transactions = $this->accountRepository->periodCollection($account, $start, $end); // loop dates Log::debug(sprintf('Count of loops: %d', count($dates))); + $loops = 0; + // stop after 10 loops for memory reasons. foreach ($dates as $currentDate) { $title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']); - [$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']); - [$transactions, $earned] = $this->filterTransactionsByType(TransactionTypeEnum::DEPOSIT, $transactions, $currentDate['start'], $currentDate['end']); - [$transactions, $transferredAway] = $this->filterTransfers('away', $transactions, $currentDate['start'], $currentDate['end']); - [$transactions, $transferredIn] = $this->filterTransfers('in', $transactions, $currentDate['start'], $currentDate['end']); + if($loops < 10) { + [$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']); + [$transactions, $earned] = $this->filterTransactionsByType(TransactionTypeEnum::DEPOSIT, $transactions, $currentDate['start'], $currentDate['end']); + [$transactions, $transferredAway] = $this->filterTransfers('away', $transactions, $currentDate['start'], $currentDate['end']); + [$transactions, $transferredIn] = $this->filterTransfers('in', $transactions, $currentDate['start'], $currentDate['end']); + } $entries[] = [ 'title' => $title, @@ -119,6 +127,7 @@ trait PeriodOverview 'transferred_away' => $this->groupByCurrency($transferredAway), 'transferred_in' => $this->groupByCurrency($transferredIn), ]; + $loops++; } $cache->store($entries); Timer::stop('account-period-total'); @@ -548,27 +557,29 @@ trait PeriodOverview /** @var array $dates */ $dates = app('navigation')->blockPeriods($start, $end, $range); $entries = []; - + $spent = []; + $earned = []; + $transferred = []; // collect all journals in this period (regardless of type) $collector = app(GroupCollectorInterface::class); $collector->setTypes($types)->setRange($start, $end); $genericSet = $collector->getExtractedJournals(); + $loops = 0; foreach ($dates as $currentDate) { - $spent = []; - $earned = []; - $transferred = []; $title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']); - // set to correct array - if ('expenses' === $transactionType || 'withdrawal' === $transactionType) { - $spent = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); - } - if ('revenue' === $transactionType || 'deposit' === $transactionType) { - $earned = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); - } - if ('transfer' === $transactionType || 'transfers' === $transactionType) { - $transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); + if($loops < 10) { + // set to correct array + if ('expenses' === $transactionType || 'withdrawal' === $transactionType) { + $spent = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); + } + if ('revenue' === $transactionType || 'deposit' === $transactionType) { + $earned = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); + } + if ('transfer' === $transactionType || 'transfers' === $transactionType) { + $transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']); + } } $entries[] = [ @@ -579,6 +590,7 @@ trait PeriodOverview 'earned' => $this->groupByCurrency($earned), 'transferred' => $this->groupByCurrency($transferred), ]; + $loops++; } return $entries;