mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-15 16:57:09 +00:00
Fix recurring transactions create
- If there's a lot of accounts to calculate balances for, then recurring transactions create page doesn't load. Partly because it has to calculate a lot of balances, but partly because the cache isn't being used at all because date is `new Date` rather than say, end of month. Fix: Change Steam balance calculator to always default cache using end of month. Since cache is 'invalidated' upon any edit, there's no reason to use current datetime anywhere its not explicitly required by user flow. Fix: Don't calculate balances for revenue / expense accounts since those are unbounded. Issue: #3597
This commit is contained in:
@@ -40,12 +40,14 @@ class Steam
|
||||
{
|
||||
|
||||
/**
|
||||
* Gets balance at the end of current month by default
|
||||
*
|
||||
* @param \FireflyIII\Models\Account $account
|
||||
* @param \Carbon\Carbon $date
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function balance(Account $account, Carbon $date, ?TransactionCurrency $currency = null): string
|
||||
public function balance(Account $account, Carbon $date = null, ?TransactionCurrency $currency = null): string
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
@@ -58,6 +60,9 @@ class Steam
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
if (null === $date) {
|
||||
$date = Carbon::now()->endOfMonth();
|
||||
}
|
||||
/** @var AccountRepositoryInterface $repository */
|
||||
$repository = app(AccountRepositoryInterface::class);
|
||||
if (null === $currency) {
|
||||
@@ -255,12 +260,14 @@ class Steam
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets balance at the end of current month by default
|
||||
*
|
||||
* @param \FireflyIII\Models\Account $account
|
||||
* @param \Carbon\Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balancePerCurrency(Account $account, Carbon $date): array
|
||||
public function balancePerCurrency(Account $account, Carbon $date = null): array
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
@@ -273,6 +280,9 @@ class Steam
|
||||
if ($cache->has()) {
|
||||
return $cache->get(); // @codeCoverageIgnore
|
||||
}
|
||||
if (null === $date) {
|
||||
$date = Carbon::now()->endOfMonth();
|
||||
}
|
||||
$query = $account->transactions()
|
||||
->leftJoin('transaction_journals', 'transaction_journals.id', '=', 'transactions.transaction_journal_id')
|
||||
->where('transaction_journals.date', '<=', $date->format('Y-m-d 23:59:59'))
|
||||
@@ -289,14 +299,14 @@ class Steam
|
||||
}
|
||||
|
||||
/**
|
||||
* This method always ignores the virtual balance.
|
||||
* This method always ignores the virtual balance. Gets balance at the end of current month by default
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $accounts
|
||||
* @param \Carbon\Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balancesByAccounts(Collection $accounts, Carbon $date): array
|
||||
public function balancesByAccounts(Collection $accounts, Carbon $date = null): array
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
@@ -324,14 +334,14 @@ class Steam
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as above, but also groups per currency.
|
||||
* Same as above, but also groups per currency. Gets balance at the end of current month by default
|
||||
*
|
||||
* @param \Illuminate\Support\Collection $accounts
|
||||
* @param \Carbon\Carbon $date
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date): array
|
||||
public function balancesPerCurrencyByAccounts(Collection $accounts, Carbon $date = null): array
|
||||
{
|
||||
if ('testing' === config('app.env')) {
|
||||
Log::warning(sprintf('%s should NOT be called in the TEST environment!', __METHOD__));
|
||||
|
Reference in New Issue
Block a user