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

@@ -61,10 +61,10 @@ trait UserGroupTrait
/**
* @throws FireflyException
*/
public function setUser(Authenticatable|User|null $user): void
public function setUser(Authenticatable | User | null $user): void
{
if ($user instanceof User) {
$this->user = $user;
$this->user = $user;
if (null === $user->userGroup) {
throw new FireflyException(sprintf('User #%d ("%s") has no user group.', $user->id, $user->email));
}
@@ -99,15 +99,14 @@ trait UserGroupTrait
public function setUserGroupById(int $userGroupId): void
{
$memberships = GroupMembership::where('user_id', $this->user->id)
->where('user_group_id', $userGroupId)
->count()
;
->where('user_group_id', $userGroupId)
->count();
if (0 === $memberships) {
throw new FireflyException(sprintf('User #%d has no access to administration #%d', $this->user->id, $userGroupId));
}
/** @var null|UserGroup $userGroup */
$userGroup = UserGroup::find($userGroupId);
$userGroup = UserGroup::find($userGroupId);
if (null === $userGroup) {
throw new FireflyException(sprintf('Cannot find administration for user #%d', $this->user->id));
}