From d84405191f27d24a4a80111e4b2ddf15eabe683a Mon Sep 17 00:00:00 2001 From: James Cole Date: Sun, 9 Mar 2025 09:53:19 +0100 Subject: [PATCH] Add debug timers. --- .../Controllers/Account/ShowController.php | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/Account/ShowController.php b/app/Http/Controllers/Account/ShowController.php index 24ac82cea2..a2b7a027a9 100644 --- a/app/Http/Controllers/Account/ShowController.php +++ b/app/Http/Controllers/Account/ShowController.php @@ -29,10 +29,11 @@ use FireflyIII\Exceptions\FireflyException; use FireflyIII\Helpers\Collector\GroupCollectorInterface; use FireflyIII\Http\Controllers\Controller; use FireflyIII\Models\Account; -use FireflyIII\Models\Transaction; use FireflyIII\Repositories\Account\AccountRepositoryInterface; +use FireflyIII\Support\Debug\Timer; use FireflyIII\Support\Facades\Steam; use FireflyIII\Support\Http\Controllers\PeriodOverview; +use FireflyIII\Support\JsonApi\Enrichments\TransactionGroupEnrichment; use Illuminate\Contracts\View\Factory; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -82,7 +83,7 @@ class ShowController extends Controller public function show(Request $request, Account $account, ?Carbon $start = null, ?Carbon $end = null) { - $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); + $objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type)); if (!$this->isEditableAccount($account)) { return $this->redirectAccountToAccount($account); @@ -114,33 +115,55 @@ class ShowController extends Controller $subTitle = (string) trans('firefly.journals_in_period_for_account', ['name' => $account->name, 'start' => $fStart, 'end' => $fEnd]); $chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); $firstTransaction = $this->repository->oldestJournalDate($account) ?? $start; + + Log::debug('Start period overview'); + Timer::start('period-overview'); + $periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end); + Log::debug('End period overview'); + Timer::stop('period-overview'); + // if layout = v2, overrule the page title. if ('v1' !== config('view.layout')) { $subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]); } - + Log::debug('Collect transactions'); + Timer::start('collection'); /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); - $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation()->setRange($start, $end); - + $collector = app(GroupCollectorInterface::class); + $collector + ->setAccounts(new Collection([$account])) + ->setLimit($pageSize) + ->setPage($page) + ->withAPIInformation() + ->setRange($start, $end); // this search will not include transaction groups where this asset account (or liability) // is just part of ONE of the journals. To force this: $collector->setExpandGroupSearch(true); + $groups = $collector->getPaginatedGroups(); + + Log::debug('End collect transactions'); + Timer::stop('collection'); + + // enrich data in arrays. + + // enrich +// $enrichment = new TransactionGroupEnrichment(); +// $enrichment->setUser(auth()->user()); +// $groups->setCollection($enrichment->enrich($groups->getCollection())); - $groups = $collector->getPaginatedGroups(); $groups->setPath(route('accounts.show', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')])); - $showAll = false; + $showAll = false; // correct - $now = today()->endOfDay(); + $now = today()->endOfDay(); if ($now->gt($end) || $now->lt($start)) { $now = $end; } Log::debug(sprintf('show: Call finalAccountBalance with date/time "%s"', $now->toIso8601String())); - $balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $now), $account, $this->convertToNative, $accountCurrency); + $balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $now), $account, $this->convertToNative, $accountCurrency); return view( 'accounts.show', @@ -184,7 +207,7 @@ class ShowController extends Controller $today = today(config('app.timezone')); $accountCurrency = $this->repository->getAccountCurrency($account); $start = $this->repository->oldestJournalDate($account) ?? today(config('app.timezone'))->startOfMonth(); - $subTitleIcon = config('firefly.subIconsByIdentifier.'.$account->accountType->type); + $subTitleIcon = config('firefly.subIconsByIdentifier.' . $account->accountType->type); $page = (int) $request->get('page'); $pageSize = (int) app('preferences')->get('listPageSize', 50)->data; $currency = $this->repository->getAccountCurrency($account) ?? $this->defaultCurrency; @@ -194,20 +217,20 @@ class ShowController extends Controller $end->endOfDay(); /** @var GroupCollectorInterface $collector */ - $collector = app(GroupCollectorInterface::class); + $collector = app(GroupCollectorInterface::class); $collector->setAccounts(new Collection([$account]))->setLimit($pageSize)->setPage($page)->withAccountInformation()->withCategoryInformation(); // this search will not include transaction groups where this asset account (or liability) // is just part of ONE of the journals. To force this: $collector->setExpandGroupSearch(true); - $groups = $collector->getPaginatedGroups(); + $groups = $collector->getPaginatedGroups(); $groups->setPath(route('accounts.show.all', [$account->id])); - $chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); - $showAll = true; + $chartUrl = route('chart.account.period', [$account->id, $start->format('Y-m-d'), $end->format('Y-m-d')]); + $showAll = true; // correct Log::debug(sprintf('showAll: Call finalAccountBalance with date/time "%s"', $end->toIso8601String())); - $balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); + $balances = Steam::filterAccountBalance(Steam::finalAccountBalance($account, $end), $account, $this->convertToNative, $accountCurrency); return view( 'accounts.show',