mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Fewer loops.
This commit is contained in:
@@ -70,7 +70,7 @@ trait PeriodOverview
|
|||||||
protected JournalRepositoryInterface $journalRepos;
|
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
|
* and for each period, the amount of money spent and earned. This is a complex operation which is cached for
|
||||||
* performance reasons.
|
* performance reasons.
|
||||||
*
|
*
|
||||||
@@ -97,18 +97,26 @@ trait PeriodOverview
|
|||||||
/** @var array $dates */
|
/** @var array $dates */
|
||||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||||
$entries = [];
|
$entries = [];
|
||||||
|
$spent= [];
|
||||||
|
$earned = [];
|
||||||
|
$transferredAway = [];
|
||||||
|
$transferredIn = [];
|
||||||
|
|
||||||
// run a custom query because doing this with the collector is MEGA slow.
|
// run a custom query because doing this with the collector is MEGA slow.
|
||||||
$transactions = $this->accountRepository->periodCollection($account, $start, $end);
|
$transactions = $this->accountRepository->periodCollection($account, $start, $end);
|
||||||
|
|
||||||
// loop dates
|
// loop dates
|
||||||
Log::debug(sprintf('Count of loops: %d', count($dates)));
|
Log::debug(sprintf('Count of loops: %d', count($dates)));
|
||||||
|
$loops = 0;
|
||||||
|
// stop after 10 loops for memory reasons.
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
$title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
|
$title = app('navigation')->periodShow($currentDate['start'], $currentDate['period']);
|
||||||
|
if($loops < 10) {
|
||||||
[$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']);
|
[$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']);
|
||||||
[$transactions, $earned] = $this->filterTransactionsByType(TransactionTypeEnum::DEPOSIT, $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, $transferredAway] = $this->filterTransfers('away', $transactions, $currentDate['start'], $currentDate['end']);
|
||||||
[$transactions, $transferredIn] = $this->filterTransfers('in', $transactions, $currentDate['start'], $currentDate['end']);
|
[$transactions, $transferredIn] = $this->filterTransfers('in', $transactions, $currentDate['start'], $currentDate['end']);
|
||||||
|
}
|
||||||
$entries[]
|
$entries[]
|
||||||
= [
|
= [
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
@@ -119,6 +127,7 @@ trait PeriodOverview
|
|||||||
'transferred_away' => $this->groupByCurrency($transferredAway),
|
'transferred_away' => $this->groupByCurrency($transferredAway),
|
||||||
'transferred_in' => $this->groupByCurrency($transferredIn),
|
'transferred_in' => $this->groupByCurrency($transferredIn),
|
||||||
];
|
];
|
||||||
|
$loops++;
|
||||||
}
|
}
|
||||||
$cache->store($entries);
|
$cache->store($entries);
|
||||||
Timer::stop('account-period-total');
|
Timer::stop('account-period-total');
|
||||||
@@ -548,18 +557,19 @@ trait PeriodOverview
|
|||||||
/** @var array $dates */
|
/** @var array $dates */
|
||||||
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
$dates = app('navigation')->blockPeriods($start, $end, $range);
|
||||||
$entries = [];
|
$entries = [];
|
||||||
|
$spent = [];
|
||||||
|
$earned = [];
|
||||||
|
$transferred = [];
|
||||||
// collect all journals in this period (regardless of type)
|
// collect all journals in this period (regardless of type)
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
$collector->setTypes($types)->setRange($start, $end);
|
$collector->setTypes($types)->setRange($start, $end);
|
||||||
$genericSet = $collector->getExtractedJournals();
|
$genericSet = $collector->getExtractedJournals();
|
||||||
|
$loops = 0;
|
||||||
|
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
$spent = [];
|
|
||||||
$earned = [];
|
|
||||||
$transferred = [];
|
|
||||||
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
$title = app('navigation')->periodShow($currentDate['end'], $currentDate['period']);
|
||||||
|
|
||||||
|
if($loops < 10) {
|
||||||
// set to correct array
|
// set to correct array
|
||||||
if ('expenses' === $transactionType || 'withdrawal' === $transactionType) {
|
if ('expenses' === $transactionType || 'withdrawal' === $transactionType) {
|
||||||
$spent = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']);
|
$spent = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']);
|
||||||
@@ -570,6 +580,7 @@ trait PeriodOverview
|
|||||||
if ('transfer' === $transactionType || 'transfers' === $transactionType) {
|
if ('transfer' === $transactionType || 'transfers' === $transactionType) {
|
||||||
$transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']);
|
$transferred = $this->filterJournalsByDate($genericSet, $currentDate['start'], $currentDate['end']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
$entries[]
|
$entries[]
|
||||||
= [
|
= [
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
@@ -579,6 +590,7 @@ trait PeriodOverview
|
|||||||
'earned' => $this->groupByCurrency($earned),
|
'earned' => $this->groupByCurrency($earned),
|
||||||
'transferred' => $this->groupByCurrency($transferred),
|
'transferred' => $this->groupByCurrency($transferred),
|
||||||
];
|
];
|
||||||
|
$loops++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
|
Reference in New Issue
Block a user