From 268c3756437c1e53d71cb8338e478813c2263dea Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Wed, 8 Jul 2026 10:50:57 +0200 Subject: [PATCH] perf: Don't fetch full group information This is expensive and not needed Signed-off-by: Carl Schwan --- lib/Service/GroupSharingService.php | 8 +++----- tests/unit/Service/GroupSharingServiceTest.php | 13 +++---------- 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/Service/GroupSharingService.php b/lib/Service/GroupSharingService.php index 988d48b69..4a18cede1 100644 --- a/lib/Service/GroupSharingService.php +++ b/lib/Service/GroupSharingService.php @@ -10,7 +10,6 @@ namespace OCA\Contacts\Service; use OCP\IConfig; -use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\Share\IManager as IShareManager; @@ -29,8 +28,7 @@ public function isGroupSharingAllowed(IUser $user): bool { return false; } - $userGroups = $this->groupManager->getUserGroups($user); - $userGroupNames = array_map(static fn (IGroup $group) => $group->getGID(), $userGroups); + $userGroupIds = $this->groupManager->getUserGroupIds($user); $excludeGroupList = json_decode($this->config->getAppValue('core', 'shareapi_exclude_groups_list', '[]'), true); $excludeGroups = $this->config->getAppValue('core', 'shareapi_exclude_groups'); @@ -39,8 +37,8 @@ public function isGroupSharingAllowed(IUser $user): bool { // "yes" => Exclude listed groups from sharing // "allow" => Limit sharing to listed groups return match ($excludeGroups) { - 'yes' => count(array_intersect($userGroupNames, $excludeGroupList)) === 0, - 'allow' => count(array_intersect($userGroupNames, $excludeGroupList)) > 0, + 'yes' => count(array_intersect($userGroupIds, $excludeGroupList)) === 0, + 'allow' => count(array_intersect($userGroupIds, $excludeGroupList)) > 0, default => true, }; } diff --git a/tests/unit/Service/GroupSharingServiceTest.php b/tests/unit/Service/GroupSharingServiceTest.php index 42b89fda7..46e6c4236 100644 --- a/tests/unit/Service/GroupSharingServiceTest.php +++ b/tests/unit/Service/GroupSharingServiceTest.php @@ -12,7 +12,6 @@ use ChristophWurst\Nextcloud\Testing\TestCase; use OCA\Contacts\Service\GroupSharingService; use OCP\IConfig; -use OCP\IGroup; use OCP\IGroupManager; use OCP\IUser; use OCP\Share\IManager as IShareManager; @@ -78,21 +77,15 @@ public function testIsGroupSharingAllowed( string $excludeGroups, ): void { $user = $this->createMock(IUser::class); - $group1 = $this->createMock(IGroup::class); - $group1->method('getGID') - ->willReturn('group1'); - $group2 = $this->createMock(IGroup::class); - $group2->method('getGID') - ->willReturn('group2'); $this->shareManager->expects(self::once()) ->method('allowGroupSharing') ->willReturn($allowGroupSharing); if ($allowGroupSharing) { $this->groupManager->expects(self::once()) - ->method('getUserGroups') + ->method('getUserGroupIds') ->with($user) - ->willReturn([$group1, $group2]); + ->willReturn(['group1', 'group2']); $this->config->expects(self::exactly(2)) ->method('getAppValue') ->willReturnMap([ @@ -101,7 +94,7 @@ public function testIsGroupSharingAllowed( ]); } else { $this->groupManager->expects(self::never()) - ->method('getUserGroups'); + ->method('getUserGroupIds'); $this->config->expects(self::never()) ->method('getAppValue'); }