Make note of some query heavy pages.

This commit is contained in:
James Cole 2020-08-02 09:26:14 +02:00
parent 384854b353
commit 386c067e93
No known key found for this signature in database
GPG Key ID: B5669F9493CDE38D
3 changed files with 9 additions and 3 deletions

View File

@ -152,13 +152,15 @@ class IndexController extends Controller
}
$collection = $this->repository->getActiveAccountsByType($types);
$total = $collection->count();
$page = 0 === (int) $request->get('page') ? 1 : (int) $request->get('page');
$pageSize = (int) app('preferences')->get('listPageSize', 50)->data;
$accounts = $collection->slice(($page - 1) * $pageSize, $pageSize);
$inactiveCount = $this->repository->getInactiveAccountsByType($types)->count();
unset($collection);
/** @var Carbon $start */
$start = clone session('start', Carbon::now()->startOfMonth());
@ -173,6 +175,7 @@ class IndexController extends Controller
$accounts->each(
function (Account $account) use ($activities, $startBalances, $endBalances) {
// TODO lots of queries executed in this block.
$account->lastActivityDate = $this->isInArray($activities, $account->id);
$account->startBalance = $this->isInArray($startBalances, $account->id);
$account->endBalance = $this->isInArray($endBalances, $account->id);
@ -183,7 +186,6 @@ class IndexController extends Controller
$account->location = $this->repository->getLocation($account);
}
);
// make paginator:
$accounts = new LengthAwarePaginator($accounts, $total, $pageSize, $page);
$accounts->setPath(route('accounts.index', [$objectType]));

View File

@ -76,7 +76,9 @@ class AmountFormat extends AbstractExtension
/**
* Will format the amount by the currency related to the given account.
*
* @return TwigFunction;
* @return TwigFunction
* @deprecated
* TODO remove me because it executes a query in a view.
*/
protected function formatAmountByAccount(): TwigFunction
{

View File

@ -225,6 +225,8 @@ class General extends AbstractExtension
/**
* @return TwigFunction
* @deprecated because it uses a query in a view
* TODO remove me.
*/
protected function getMetaField(): TwigFunction
{