Skip to content

Commit 7b3fa5b

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 fe19ec8 commit 7b3fa5b

3 files changed

Lines changed: 5 additions & 19 deletions

File tree

apps/provisioning_api/lib/Controller/AUserDataOCSController.php

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

104104
// Get groups data
105105
$userAccount = $this->accountManager->getAccount($targetUserObject);
106-
$groups = $this->groupManager->getUserGroups($targetUserObject);
107-
$gids = [];
108-
foreach ($groups as $group) {
109-
$gids[] = $group->getGID();
110-
}
106+
$gids = $this->groupManager->getUserGroupIds($targetUserObject);
111107

112108
if ($isAdmin || $isDelegatedAdmin) {
113109
try {

apps/provisioning_api/lib/Controller/UsersController.php

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

10771077
if ($groups !== null) {
1078-
$currentGroups = $this->groupManager->getUserGroups($targetUser);
1079-
$currentGroupIds = array_map(fn (IGroup $g) => $g->getGID(), $currentGroups);
1078+
$currentGroupIds = $this->groupManager->getUserGroupIds($targetUser);
10801079
foreach (array_diff($currentGroupIds, $groups) as $gid) {
10811080
$this->groupManager->get($gid)?->removeUser($targetUser);
10821081
}

apps/provisioning_api/tests/Controller/UsersControllerTest.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,8 +1110,8 @@ public function testGetUserDataAsAdmin(): void {
11101110
->willReturn(true);
11111111
$this->groupManager
11121112
->expects($this->any())
1113-
->method('getUserGroups')
1114-
->willReturn([$group0, $group1, $group2]);
1113+
->method('getUserGroupIds')
1114+
->willReturn(['group0', 'group1', 'group2']);
11151115
$this->groupManager
11161116
->expects($this->once())
11171117
->method('getSubAdmin')
@@ -1120,15 +1120,6 @@ public function testGetUserDataAsAdmin(): void {
11201120
->expects($this->once())
11211121
->method('getSubAdminsGroups')
11221122
->willReturn([$group3]);
1123-
$group0->expects($this->once())
1124-
->method('getGID')
1125-
->willReturn('group0');
1126-
$group1->expects($this->once())
1127-
->method('getGID')
1128-
->willReturn('group1');
1129-
$group2->expects($this->once())
1130-
->method('getGID')
1131-
->willReturn('group2');
11321123
$group3->expects($this->once())
11331124
->method('getGID')
11341125
->willReturn('group3');
@@ -2668,7 +2659,7 @@ public function testUpdateUserGroupDiff(): void {
26682659
$newGroup = $this->createMock(IGroup::class);
26692660
$newGroup->method('getGID')->willReturn('newgroup');
26702661

2671-
$this->groupManager->method('getUserGroups')->willReturn([$oldGroup]);
2662+
$this->groupManager->method('getUserGroupIds')->willReturn(['oldgroup']);
26722663
$this->groupManager->method('groupExists')->willReturn(true);
26732664
$this->groupManager->method('get')->willReturnMap([
26742665
['newgroup', $newGroup],

0 commit comments

Comments
 (0)