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
3 changed files with 9 additions and 3 deletions

View File

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

View File

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