From af039a31d677efd90c1fcf78da1ca24913e974f5 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 18 Nov 2024 12:05:12 +0100 Subject: [PATCH] fix(circles): Use `probeCircles()` instead of `getCircles()` `probeCircles()` is lighter and more performant. Fixes: #498 Signed-off-by: Jonas --- lib/Service/CircleHelper.php | 11 +++++++---- lib/Service/CollectiveHelper.php | 9 +++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/lib/Service/CircleHelper.php b/lib/Service/CircleHelper.php index c39c4afe53..8c4537549b 100644 --- a/lib/Service/CircleHelper.php +++ b/lib/Service/CircleHelper.php @@ -18,6 +18,7 @@ use OCA\Circles\Model\FederatedUser; use OCA\Circles\Model\Member; use OCA\Circles\Model\Probes\CircleProbe; +use OCA\Circles\Model\Probes\DataProbe; use OCA\Circles\Tools\Exceptions\InvalidItemException; use OCP\AppFramework\QueryException; use OCP\AutoloadNotAllowedException; @@ -88,9 +89,11 @@ private function startSuperSession(): void { public function getCircles(?string $userId = null): array { try { $this->startSession($userId); - $probe = new CircleProbe(); - $probe->mustBeMember(); - $circles = $this->circlesManager->getCircles($probe, true); + $circleProbe = new CircleProbe(); + $circleProbe->mustBeMember(); + $dataProbe = new DataProbe(); + $dataProbe->add(DataProbe::INITIATOR); + $circles = $this->circlesManager->probeCircles($circleProbe, $dataProbe); } catch (RequestBuilderException| FederatedItemException $e) { throw new NotPermittedException($e->getMessage(), 0, $e); @@ -149,7 +152,7 @@ public function findCircle(string $name, string $userId, int $level = Member::LE private function existsCircle(string $name): bool { $this->circlesManager->startSuperSession(); try { - $circles = $this->circlesManager->getCircles(); + $circles = $this->circlesManager->probeCircles(); } catch (InitiatorNotFoundException|RequestBuilderException $e) { throw new NotPermittedException($e->getMessage(), 0, $e); } diff --git a/lib/Service/CollectiveHelper.php b/lib/Service/CollectiveHelper.php index 9c3d1f13aa..b0cb0f1bdd 100644 --- a/lib/Service/CollectiveHelper.php +++ b/lib/Service/CollectiveHelper.php @@ -28,7 +28,7 @@ public function __construct( */ public function getCollectivesForUser(string $userId, bool $getLevel = true, bool $getUserSettings = true): array { $circles = $this->circleHelper->getCircles($userId); - $cids = array_map(fn ($circle) => $circle->getSingleId(), $circles); + $cids = array_map(static fn ($circle) => $circle->getSingleId(), $circles); $circles = array_combine($cids, $circles); /** @var Collective[] $collectives */ $collectives = $this->collectiveMapper->findByCircleIds($cids); @@ -55,13 +55,14 @@ public function getCollectivesForUser(string $userId, bool $getLevel = true, boo */ public function getCollectivesTrashForUser(string $userId): array { $circles = $this->circleHelper->getCircles($userId); - $cids = array_map(fn ($circle) => $circle->getSingleId(), $circles); + $cids = array_map(static fn ($circle) => $circle->getSingleId(), $circles); $circles = array_combine($cids, $circles); $collectives = $this->collectiveMapper->findTrashByCircleIdsAndUser($cids, $userId); foreach ($collectives as $c) { $cid = $c->getCircleId(); - $c->setName($circles[$cid]->getSanitizedName()); - $c->setLevel($this->circleHelper->getLevel($cid, $userId)); + $circle = $circles[$cid]; + $c->setName($circle->getSanitizedName()); + $c->setLevel($circle->getInitiator()->getLevel()); } return $collectives; }