From cd9f8be5637cae9c17256195757996a2f1e460ea Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 22 Jul 2025 13:25:16 +0100 Subject: [PATCH 1/2] Optimize for when we already have the counts Signed-off-by: snipe --- app/Models/User.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Models/User.php b/app/Models/User.php index 1cb00cece5..416c97bc57 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -288,13 +288,15 @@ class User extends SnipeModel implements AuthenticatableContract, AuthorizableCo */ public function isDeletable() { + return Gate::allows('delete', $this) - && ($this->assets->count() === 0) - && ($this->licenses->count() === 0) - && ($this->consumables->count() === 0) - && ($this->accessories->count() === 0) - && ($this->managedLocations->count() === 0) - && ($this->managesUsers->count() === 0) + && (($this->assets_count ?? $this->assets()->count()) === 0) + && (($this->accessories_count ?? $this->accessories()->count()) === 0) + && (($this->licenses_count ?? $this->licenses()->count()) === 0) + && (($this->consumables_count ?? $this->consumables()->count()) === 0) + && (($this->accessories_count ?? $this->accessories()->count()) === 0) + && (($this->manages_users_count ?? $this->managesUsers()->count()) === 0) + && (($this->manages_locations_count ?? $this->managedLocations()->count()) === 0) && ($this->deleted_at == ''); } From 2cb18e366868852733b69d19774ca71a437ea382 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 22 Jul 2025 13:25:41 +0100 Subject: [PATCH 2/2] Remove fields from query - eulas was querying actionlogs Signed-off-by: snipe --- app/Http/Controllers/Api/UsersController.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Http/Controllers/Api/UsersController.php b/app/Http/Controllers/Api/UsersController.php index 15e6f7655e..afbe423b53 100644 --- a/app/Http/Controllers/Api/UsersController.php +++ b/app/Http/Controllers/Api/UsersController.php @@ -81,7 +81,12 @@ class UsersController extends Controller 'users.autoassign_licenses', 'users.website', - ])->with('manager', 'groups', 'userloc', 'company', 'department', 'assets', 'licenses', 'accessories', 'consumables', 'createdBy', 'managesUsers', 'managedLocations', 'eulas') + ])->with('manager') + ->with('groups') + ->with('userloc') + ->with('company') + ->with('department') + ->with('createdBy') ->withCount([ 'assets as assets_count' => function(Builder $query) { $query->withoutTrashed();