Skip to content

Commit 0d1fc05

Browse files
committed
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 <carlschwan@kde.org>
1 parent eb85e51 commit 0d1fc05

4 files changed

Lines changed: 9 additions & 23 deletions

File tree

apps/provisioning_api/lib/Controller/AUserDataOCSController.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,7 @@ protected function getUserData(string $userId, bool $includeScopes = false): ?ar
106106

107107
// Get groups data
108108
$userAccount = $this->accountManager->getAccount($targetUserObject);
109-
$groups = $this->groupManager->getUserGroups($targetUserObject);
110-
$gids = [];
111-
foreach ($groups as $group) {
112-
$gids[] = $group->getGID();
113-
}
109+
$gids = $this->groupManager->getUserGroupIds($targetUserObject);
114110

115111
if ($isAdmin || $isDelegatedAdmin) {
116112
try {

apps/provisioning_api/lib/Controller/UsersController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,8 +1080,7 @@ public function editUserMultiField(
10801080
}
10811081

10821082
if ($groups !== null) {
1083-
$currentGroups = $this->groupManager->getUserGroups($targetUser);
1084-
$currentGroupIds = array_map(fn (IGroup $g) => $g->getGID(), $currentGroups);
1083+
$currentGroupIds = $this->groupManager->getUserGroupIds($targetUser);
10851084
foreach (array_diff($currentGroupIds, $groups) as $gid) {
10861085
$this->groupManager->get($gid)?->removeUser($targetUser);
10871086
}

apps/provisioning_api/tests/Controller/GroupsControllerTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -483,8 +483,8 @@ public function testGetGroupUsersDetails(): void {
483483
->with($gid)
484484
->willReturn($group);
485485
$this->groupManager->expects($this->any())
486-
->method('getUserGroups')
487-
->willReturn([$group]);
486+
->method('getUserGroupIds')
487+
->willReturn(['ncg1']);
488488

489489
/** @var MockObject */
490490
$this->subAdminManager->expects($this->any())
@@ -538,8 +538,8 @@ public function testGetGroupUsersDetailsEncoded(): void {
538538
->with($gid)
539539
->willReturn($group);
540540
$this->groupManager->expects($this->any())
541-
->method('getUserGroups')
542-
->willReturn([$group]);
541+
->method('getUserGroupIds')
542+
->willReturn(['Department A/B C/D']);
543543

544544
/** @var MockObject */
545545
$this->subAdminManager->expects($this->any())

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,8 +1196,8 @@ public function testGetUserDataAsAdmin(): void {
11961196
->willReturn(true);
11971197
$this->groupManager
11981198
->expects($this->any())
1199-
->method('getUserGroups')
1200-
->willReturn([$group0, $group1, $group2]);
1199+
->method('getUserGroupIds')
1200+
->willReturn(['group0', 'group1', 'group2']);
12011201
$this->groupManager
12021202
->expects($this->once())
12031203
->method('getSubAdmin')
@@ -1206,15 +1206,6 @@ public function testGetUserDataAsAdmin(): void {
12061206
->expects($this->once())
12071207
->method('getSubAdminsGroups')
12081208
->willReturn([$group3]);
1209-
$group0->expects($this->exactly(1))
1210-
->method('getGID')
1211-
->willReturn('group0');
1212-
$group1->expects($this->exactly(1))
1213-
->method('getGID')
1214-
->willReturn('group1');
1215-
$group2->expects($this->exactly(1))
1216-
->method('getGID')
1217-
->willReturn('group2');
12181209
$group3->expects($this->once())
12191210
->method('getGID')
12201211
->willReturn('group3');
@@ -2759,7 +2750,7 @@ public function testUpdateUserGroupDiff(): void {
27592750
$newGroup = $this->createMock(IGroup::class);
27602751
$newGroup->method('getGID')->willReturn('newgroup');
27612752

2762-
$this->groupManager->method('getUserGroups')->willReturn([$oldGroup]);
2753+
$this->groupManager->method('getUserGroupIds')->willReturn(['oldgroup']);
27632754
$this->groupManager->method('groupExists')->willReturn(true);
27642755
$this->groupManager->method('get')->willReturnMap([
27652756
['newgroup', $newGroup],

0 commit comments

Comments
 (0)