Skip to content

Commit 778ef26

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 778ef26

3 files changed

Lines changed: 6 additions & 23 deletions

File tree

lib/Helper/UserHelper.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
namespace OCA\Tables\Helper;
99

1010
use OCA\Tables\Errors\InternalError;
11-
use OCP\IGroup;
1211
use OCP\IGroupManager;
1312
use OCP\IUser;
1413
use OCP\IUserManager;
@@ -48,30 +47,16 @@ private function getUser(string $userId): IUser {
4847
throw new InternalError('User not found for ' . $userId);
4948
}
5049

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-
6150
/**
6251
* @param string $userId
6352
* @return array|null
6453
*/
6554
public function getGroupIdsForUser(string $userId): ?array {
6655
try {
67-
$userGroups = $this->getGroupsForUser($userId);
56+
$user = $this->getUser($userId);
57+
return $this->groupManager->getUserGroupIds($user);
6858
} catch (InternalError $e) {
6959
return null;
7060
}
71-
72-
$groupArray = array_map(function (IGroup $group) {
73-
return $group->getGID();
74-
}, $userGroups);
75-
return $groupArray;
7661
}
7762
}

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 & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
use OCP\AppFramework\Db\TTransactional;
4040
use OCP\DB\Exception;
4141
use OCP\IDBConnection;
42-
use OCP\IGroup;
4342
use OCP\IUserManager;
4443
use OCP\Security\IHasher;
4544
use OCP\Security\ISecureRandom;
@@ -234,8 +233,7 @@ private function findElementsSharedWithMe(string $elementType = 'table', ?string
234233
try {
235234
$shares['user'] = $this->mapper->findAllSharesFor($elementType, [$userId], $userId);
236235

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

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

0 commit comments

Comments
 (0)