mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-25 14:58:40 +00:00
Expand some timers, fix reports.
This commit is contained in:
@@ -85,7 +85,8 @@ class AccountController extends Controller
|
|||||||
$query = $data['query'];
|
$query = $data['query'];
|
||||||
$date = $data['date'] ?? today(config('app.timezone'));
|
$date = $data['date'] ?? today(config('app.timezone'));
|
||||||
$return = [];
|
$return = [];
|
||||||
Timer::start(sprintf('AC accounts "%s"', $query));
|
$timer = Timer::getInstance();
|
||||||
|
$timer->start(sprintf('AC accounts "%s"', $query));
|
||||||
$result = $this->repository->searchAccount((string) $query, $types, $this->parameters->get('limit'));
|
$result = $this->repository->searchAccount((string) $query, $types, $this->parameters->get('limit'));
|
||||||
|
|
||||||
// set date to subday + end-of-day for account balance. so it is at $date 23:59:59
|
// set date to subday + end-of-day for account balance. so it is at $date 23:59:59
|
||||||
@@ -137,7 +138,7 @@ class AccountController extends Controller
|
|||||||
return $posA - $posB;
|
return $posA - $posB;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
Timer::stop(sprintf('AC accounts "%s"', $query));
|
$timer->stop(sprintf('AC accounts "%s"', $query));
|
||||||
|
|
||||||
return response()->api($return);
|
return response()->api($return);
|
||||||
}
|
}
|
||||||
|
@@ -40,6 +40,7 @@ use Illuminate\Routing\Redirector;
|
|||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\View\View;
|
use Illuminate\View\View;
|
||||||
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class ShowController
|
* Class ShowController
|
||||||
@@ -81,7 +82,9 @@ class ShowController extends Controller
|
|||||||
* */
|
* */
|
||||||
public function show(Request $request, Account $account, ?Carbon $start = null, ?Carbon $end = null)
|
public function show(Request $request, Account $account, ?Carbon $start = null, ?Carbon $end = null)
|
||||||
{
|
{
|
||||||
|
if(0 === $account->id) {
|
||||||
|
throw new NotFoundHttpException();
|
||||||
|
}
|
||||||
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
|
$objectType = config(sprintf('firefly.shortNamesByFullName.%s', $account->accountType->type));
|
||||||
|
|
||||||
if (!$this->isEditableAccount($account)) {
|
if (!$this->isEditableAccount($account)) {
|
||||||
@@ -116,18 +119,19 @@ class ShowController extends Controller
|
|||||||
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
|
$firstTransaction = $this->repository->oldestJournalDate($account) ?? $start;
|
||||||
|
|
||||||
Log::debug('Start period overview');
|
Log::debug('Start period overview');
|
||||||
Timer::start('period-overview');
|
$timer = Timer::getInstance();
|
||||||
|
$timer->start('period-overview');
|
||||||
$periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end);
|
$periods = $this->getAccountPeriodOverview($account, $firstTransaction, $end);
|
||||||
|
|
||||||
Log::debug('End period overview');
|
Log::debug('End period overview');
|
||||||
Timer::stop('period-overview');
|
$timer->stop('period-overview');
|
||||||
|
|
||||||
// if layout = v2, overrule the page title.
|
// if layout = v2, overrule the page title.
|
||||||
if ('v1' !== config('view.layout')) {
|
if ('v1' !== config('view.layout')) {
|
||||||
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
$subTitle = (string) trans('firefly.all_journals_for_account', ['name' => $account->name]);
|
||||||
}
|
}
|
||||||
Log::debug('Collect transactions');
|
Log::debug('Collect transactions');
|
||||||
Timer::start('collection');
|
$timer->start('collection');
|
||||||
|
|
||||||
/** @var GroupCollectorInterface $collector */
|
/** @var GroupCollectorInterface $collector */
|
||||||
$collector = app(GroupCollectorInterface::class);
|
$collector = app(GroupCollectorInterface::class);
|
||||||
@@ -146,7 +150,7 @@ class ShowController extends Controller
|
|||||||
|
|
||||||
|
|
||||||
Log::debug('End collect transactions');
|
Log::debug('End collect transactions');
|
||||||
Timer::stop('collection');
|
$timer->stop('collection');
|
||||||
|
|
||||||
// enrich data in arrays.
|
// enrich data in arrays.
|
||||||
|
|
||||||
|
@@ -188,16 +188,7 @@ class ReportController extends Controller
|
|||||||
$start->endOfDay(); // end of day so the final balance is at the end of that day.
|
$start->endOfDay(); // end of day so the final balance is at the end of that day.
|
||||||
$end->endOfDay();
|
$end->endOfDay();
|
||||||
|
|
||||||
app('view')->share(
|
app('view')->share('subTitle', trans('firefly.report_default', ['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat),]));
|
||||||
'subTitle',
|
|
||||||
trans(
|
|
||||||
'firefly.report_default',
|
|
||||||
[
|
|
||||||
'start' => $start->isoFormat($this->monthAndDayFormat),
|
|
||||||
'end' => $end->isoFormat($this->monthAndDayFormat),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$generator = ReportGeneratorFactory::reportGenerator('Standard', $start, $end);
|
$generator = ReportGeneratorFactory::reportGenerator('Standard', $start, $end);
|
||||||
$generator->setAccounts($accounts);
|
$generator->setAccounts($accounts);
|
||||||
@@ -222,16 +213,7 @@ class ReportController extends Controller
|
|||||||
$start->endOfDay(); // end of day so the final balance is at the end of that day.
|
$start->endOfDay(); // end of day so the final balance is at the end of that day.
|
||||||
$end->endOfDay();
|
$end->endOfDay();
|
||||||
|
|
||||||
app('view')->share(
|
app('view')->share('subTitle', trans('firefly.report_double', ['start' => $start->isoFormat($this->monthAndDayFormat), 'end' => $end->isoFormat($this->monthAndDayFormat),]));
|
||||||
'subTitle',
|
|
||||||
trans(
|
|
||||||
'firefly.report_double',
|
|
||||||
[
|
|
||||||
'start' => $start->isoFormat($this->monthAndDayFormat),
|
|
||||||
'end' => $end->isoFormat($this->monthAndDayFormat),
|
|
||||||
]
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end);
|
$generator = ReportGeneratorFactory::reportGenerator('Account', $start, $end);
|
||||||
$generator->setAccounts($accounts);
|
$generator->setAccounts($accounts);
|
||||||
|
@@ -28,19 +28,34 @@ use Illuminate\Support\Facades\Log;
|
|||||||
|
|
||||||
class Timer
|
class Timer
|
||||||
{
|
{
|
||||||
private static array $times = [];
|
private array $times = [];
|
||||||
|
private static ?Timer $instance = null;
|
||||||
|
|
||||||
public static function start(string $title): void
|
private function __construct()
|
||||||
{
|
{
|
||||||
self::$times[$title] = microtime(true);
|
// Private constructor to prevent direct instantiation.
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function stop(string $title): void
|
public static function getInstance(): self
|
||||||
{
|
{
|
||||||
$start = self::$times[$title] ?? 0;
|
if (null === self::$instance) {
|
||||||
|
self::$instance = new self();
|
||||||
|
}
|
||||||
|
|
||||||
|
return self::$instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function start(string $title): void
|
||||||
|
{
|
||||||
|
$this->times[$title] = microtime(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function stop(string $title): void
|
||||||
|
{
|
||||||
|
$start = $this->times[$title] ?? 0;
|
||||||
$end = microtime(true);
|
$end = microtime(true);
|
||||||
$diff = $end - $start;
|
$diff = $end - $start;
|
||||||
unset(self::$times[$title]);
|
unset($this->times[$title]);
|
||||||
Log::debug(sprintf('Timer "%s" took %f seconds', $title, $diff));
|
Log::debug(sprintf('Timer "%s" took %f seconds', $title, $diff));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -80,7 +80,8 @@ trait PeriodOverview
|
|||||||
protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array
|
protected function getAccountPeriodOverview(Account $account, Carbon $start, Carbon $end): array
|
||||||
{
|
{
|
||||||
Log::debug('Now in getAccountPeriodOverview()');
|
Log::debug('Now in getAccountPeriodOverview()');
|
||||||
Timer::start('account-period-total');
|
$timer = Timer::getInstance();
|
||||||
|
$timer->start('account-period-total');
|
||||||
$this->accountRepository = app(AccountRepositoryInterface::class);
|
$this->accountRepository = app(AccountRepositoryInterface::class);
|
||||||
$range = Navigation::getViewRange(true);
|
$range = Navigation::getViewRange(true);
|
||||||
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
[$start, $end] = $end < $start ? [$end, $start] : [$start, $end];
|
||||||
@@ -101,14 +102,14 @@ trait PeriodOverview
|
|||||||
$entries = [];
|
$entries = [];
|
||||||
|
|
||||||
// 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.
|
||||||
Timer::start('account-period-collect');
|
$timer->start('account-period-collect');
|
||||||
$transactions = $this->accountRepository->periodCollection($account, $start, $end);
|
$transactions = $this->accountRepository->periodCollection($account, $start, $end);
|
||||||
Timer::stop('account-period-collect');
|
$timer->stop('account-period-collect');
|
||||||
// loop dates
|
// loop dates
|
||||||
Log::debug(sprintf('Count of loops: %d', count($dates)));
|
Log::debug(sprintf('Count of loops: %d', count($dates)));
|
||||||
$loops = 0;
|
$loops = 0;
|
||||||
// stop after 10 loops for memory reasons.
|
// stop after 10 loops for memory reasons.
|
||||||
Timer::start('account-period-loop');
|
$timer->start('account-period-loop');
|
||||||
foreach ($dates as $currentDate) {
|
foreach ($dates as $currentDate) {
|
||||||
$title = Navigation::periodShow($currentDate['start'], $currentDate['period']);
|
$title = Navigation::periodShow($currentDate['start'], $currentDate['period']);
|
||||||
[$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']);
|
[$transactions, $spent] = $this->filterTransactionsByType(TransactionTypeEnum::WITHDRAWAL, $transactions, $currentDate['start'], $currentDate['end']);
|
||||||
@@ -127,9 +128,9 @@ trait PeriodOverview
|
|||||||
];
|
];
|
||||||
++$loops;
|
++$loops;
|
||||||
}
|
}
|
||||||
Timer::stop('account-period-loop');
|
$timer->stop('account-period-loop');
|
||||||
$cache->store($entries);
|
$cache->store($entries);
|
||||||
Timer::stop('account-period-total');
|
$timer->stop('account-period-total');
|
||||||
Log::debug('End of getAccountPeriodOverview()');
|
Log::debug('End of getAccountPeriodOverview()');
|
||||||
|
|
||||||
return $entries;
|
return $entries;
|
||||||
|
@@ -2333,6 +2333,7 @@ return [
|
|||||||
|
|
||||||
|
|
||||||
// reports:
|
// reports:
|
||||||
|
'quick_link_needs_accounts' => 'In order to generate reports, you need to add at least one asset account to Firefly III.',
|
||||||
'report_default' => 'Default financial report between :start and :end',
|
'report_default' => 'Default financial report between :start and :end',
|
||||||
'report_audit' => 'Transaction history overview between :start and :end',
|
'report_audit' => 'Transaction history overview between :start and :end',
|
||||||
'report_category' => 'Category report between :start and :end',
|
'report_category' => 'Category report between :start and :end',
|
||||||
|
@@ -128,6 +128,12 @@
|
|||||||
<h3 class="box-title">{{ 'quick_link_reports'|_ }}</h3>
|
<h3 class="box-title">{{ 'quick_link_reports'|_ }}</h3>
|
||||||
</div>
|
</div>
|
||||||
<div class="box-body">
|
<div class="box-body">
|
||||||
|
{% if '' == accountList %}
|
||||||
|
<p class="text-danger">
|
||||||
|
{{ 'quick_link_needs_accounts'|_ }}
|
||||||
|
</p>
|
||||||
|
{% endif %}
|
||||||
|
{% if '' != accountList %}
|
||||||
<p>
|
<p>
|
||||||
{{ 'quick_link_examples'|_ }}
|
{{ 'quick_link_examples'|_ }}
|
||||||
</p>
|
</p>
|
||||||
@@ -172,6 +178,7 @@
|
|||||||
<p>
|
<p>
|
||||||
<em>{{ 'reports_can_bookmark'|_ }}</em>
|
<em>{{ 'reports_can_bookmark'|_ }}</em>
|
||||||
</p>
|
</p>
|
||||||
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user