Skip to content

Commit 32e7bf4

Browse files
committed
perf: Don't fetch full group information
This is expensive particularly when multiple group backends are enabled Signed-off-by: Carl Schwan <carlschwan@kde.org>
1 parent 7e63379 commit 32e7bf4

3 files changed

Lines changed: 6 additions & 21 deletions

File tree

lib/Helper/UserHelper.php

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,30 +48,16 @@ private function getUser(string $userId): IUser {
4848
throw new InternalError('User not found for ' . $userId);
4949
}
5050

51-
/**
52-
* @param string $userId
53-
* @return IGroup[]
54-
* @throws InternalError
55-
*/
56-
public function getGroupsForUser(string $userId): array {
57-
$user = $this->getUser($userId);
58-
return $this->groupManager->getUserGroups($user);
59-
}
60-
6151
/**
6252
* @param string $userId
6353
* @return array|null
6454
*/
6555
public function getGroupIdsForUser(string $userId): ?array {
6656
try {
67-
$userGroups = $this->getGroupsForUser($userId);
57+
$user = $this->getUser($userId);
58+
return $this->groupManager->getUserGroupIds($user);
6859
} catch (InternalError $e) {
6960
return null;
7061
}
71-
72-
$groupArray = array_map(function (IGroup $group) {
73-
return $group->getGID();
74-
}, $userGroups);
75-
return $groupArray;
7662
}
7763
}

lib/Service/PermissionsService.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ public function canReadShare(Share $share, ?string $userId = null): bool {
438438

439439
if ($share->getReceiverType() === 'group') {
440440
try {
441-
$userGroups = $this->userHelper->getGroupsForUser($userId);
442-
foreach ($userGroups as $userGroup) {
443-
if ($userGroup->getGID() === $share->getReceiver()) {
441+
$userGroups = $this->userHelper->getGroupIdsForUser($userId);
442+
foreach ($userGroups as $userGroupId) {
443+
if ($userGroupId === $share->getReceiver()) {
444444
return true;
445445
}
446446
}

lib/Service/ShareService.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,7 @@ private function findElementsSharedWithMe(string $elementType = 'table', ?string
234234
try {
235235
$shares['user'] = $this->mapper->findAllSharesFor($elementType, [$userId], $userId);
236236

237-
$userGroups = $this->userHelper->getGroupsForUser($userId);
238-
$userGroupIds = array_map(static fn (IGroup $group) => $group->getGid(), $userGroups);
237+
$userGroupIds = $this->userHelper->getGroupIdsForUser($userId);
239238
$shares['groups'] = $this->mapper->findAllSharesFor($elementType, $userGroupIds, $userId, ShareReceiverType::GROUP);
240239

241240
$userCircles = $this->circleHelper->getUserCircles($userId);

0 commit comments

Comments
 (0)