From 7b3fa5bfa19397a93272095da48a54f73a35d5f0 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 8 Jul 2026 10:24:37 +0200 Subject: [PATCH] perf: Replace more calls from getUserGroups to getUserGroupIds Faster as we only need the gid and not the full group objects Signed-off-by: Carl Schwan --- .../lib/Controller/AUserDataOCSController.php | 6 +----- .../lib/Controller/UsersController.php | 3 +-- .../tests/Controller/UsersControllerTest.php | 15 +++------------ 3 files changed, 5 insertions(+), 19 deletions(-) diff --git a/apps/provisioning_api/lib/Controller/AUserDataOCSController.php b/apps/provisioning_api/lib/Controller/AUserDataOCSController.php index aeb4efe11e13a..066b9fbd400b1 100644 --- a/apps/provisioning_api/lib/Controller/AUserDataOCSController.php +++ b/apps/provisioning_api/lib/Controller/AUserDataOCSController.php @@ -103,11 +103,7 @@ protected function getUserData(string $userId, bool $includeScopes = false): ?ar // Get groups data $userAccount = $this->accountManager->getAccount($targetUserObject); - $groups = $this->groupManager->getUserGroups($targetUserObject); - $gids = []; - foreach ($groups as $group) { - $gids[] = $group->getGID(); - } + $gids = $this->groupManager->getUserGroupIds($targetUserObject); if ($isAdmin || $isDelegatedAdmin) { try { diff --git a/apps/provisioning_api/lib/Controller/UsersController.php b/apps/provisioning_api/lib/Controller/UsersController.php index 3697d6b36a2aa..f743acbb6f0db 100644 --- a/apps/provisioning_api/lib/Controller/UsersController.php +++ b/apps/provisioning_api/lib/Controller/UsersController.php @@ -1075,8 +1075,7 @@ public function editUserMultiField( } if ($groups !== null) { - $currentGroups = $this->groupManager->getUserGroups($targetUser); - $currentGroupIds = array_map(fn (IGroup $g) => $g->getGID(), $currentGroups); + $currentGroupIds = $this->groupManager->getUserGroupIds($targetUser); foreach (array_diff($currentGroupIds, $groups) as $gid) { $this->groupManager->get($gid)?->removeUser($targetUser); } diff --git a/apps/provisioning_api/tests/Controller/UsersControllerTest.php b/apps/provisioning_api/tests/Controller/UsersControllerTest.php index 20a0cf6bffc24..0b94bcc069c1d 100644 --- a/apps/provisioning_api/tests/Controller/UsersControllerTest.php +++ b/apps/provisioning_api/tests/Controller/UsersControllerTest.php @@ -1110,8 +1110,8 @@ public function testGetUserDataAsAdmin(): void { ->willReturn(true); $this->groupManager ->expects($this->any()) - ->method('getUserGroups') - ->willReturn([$group0, $group1, $group2]); + ->method('getUserGroupIds') + ->willReturn(['group0', 'group1', 'group2']); $this->groupManager ->expects($this->once()) ->method('getSubAdmin') @@ -1120,15 +1120,6 @@ public function testGetUserDataAsAdmin(): void { ->expects($this->once()) ->method('getSubAdminsGroups') ->willReturn([$group3]); - $group0->expects($this->once()) - ->method('getGID') - ->willReturn('group0'); - $group1->expects($this->once()) - ->method('getGID') - ->willReturn('group1'); - $group2->expects($this->once()) - ->method('getGID') - ->willReturn('group2'); $group3->expects($this->once()) ->method('getGID') ->willReturn('group3'); @@ -2668,7 +2659,7 @@ public function testUpdateUserGroupDiff(): void { $newGroup = $this->createMock(IGroup::class); $newGroup->method('getGID')->willReturn('newgroup'); - $this->groupManager->method('getUserGroups')->willReturn([$oldGroup]); + $this->groupManager->method('getUserGroupIds')->willReturn(['oldgroup']); $this->groupManager->method('groupExists')->willReturn(true); $this->groupManager->method('get')->willReturnMap([ ['newgroup', $newGroup],