Optimize queries for statistics.

This commit is contained in:
James Cole
2025-09-26 06:05:37 +02:00
parent 08879d31ba
commit 4ec2fcdb8a
92 changed files with 6499 additions and 6514 deletions

View File

@@ -28,7 +28,6 @@ use FireflyIII\User;
use Illuminate\Contracts\Auth\Authenticatable;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Collection;
use function Safe\json_encode;
/**
@@ -37,16 +36,16 @@ use function Safe\json_encode;
class AccountSearch implements GenericSearchInterface
{
/** @var string */
public const string SEARCH_ALL = 'all';
public const string SEARCH_ALL = 'all';
/** @var string */
public const string SEARCH_IBAN = 'iban';
public const string SEARCH_IBAN = 'iban';
/** @var string */
public const string SEARCH_ID = 'id';
public const string SEARCH_ID = 'id';
/** @var string */
public const string SEARCH_NAME = 'name';
public const string SEARCH_NAME = 'name';
/** @var string */
public const string SEARCH_NUMBER = 'number';
@@ -63,10 +62,9 @@ class AccountSearch implements GenericSearchInterface
public function search(): Collection
{
$searchQuery = $this->user->accounts()
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->whereIn('account_types.type', $this->types)
;
->leftJoin('account_types', 'accounts.account_type_id', '=', 'account_types.id')
->leftJoin('account_meta', 'accounts.id', '=', 'account_meta.account_id')
->whereIn('account_types.type', $this->types);
$like = sprintf('%%%s%%', $this->query);
$originalQuery = $this->query;
@@ -92,7 +90,7 @@ class AccountSearch implements GenericSearchInterface
break;
case self::SEARCH_ID:
$searchQuery->where('accounts.id', '=', (int) $originalQuery);
$searchQuery->where('accounts.id', '=', (int)$originalQuery);
break;
@@ -137,7 +135,7 @@ class AccountSearch implements GenericSearchInterface
$this->types = $types;
}
public function setUser(Authenticatable|User|null $user): void
public function setUser(Authenticatable | User | null $user): void
{
if ($user instanceof User) {
$this->user = $user;