Skip to content

Commit

Permalink
fix(circles): Use probeCircles() instead of getCircles()
Browse files Browse the repository at this point in the history
`probeCircles()` is lighter and more performant.

Fixes: #498

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Nov 18, 2024
1 parent a62acb0 commit af039a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
11 changes: 7 additions & 4 deletions lib/Service/CircleHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();

Check failure on line 94 in lib/Service/CircleHelper.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/CircleHelper.php:94:21: UndefinedClass: Class, interface or enum named OCA\Circles\Model\Probes\DataProbe does not exist (see https://psalm.dev/019)
$dataProbe->add(DataProbe::INITIATOR);

Check failure on line 95 in lib/Service/CircleHelper.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedClass

lib/Service/CircleHelper.php:95:20: UndefinedClass: Class, interface or enum named OCA\Circles\Model\Probes\DataProbe does not exist (see https://psalm.dev/019)
$circles = $this->circlesManager->probeCircles($circleProbe, $dataProbe);

Check failure on line 96 in lib/Service/CircleHelper.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedMethod

lib/Service/CircleHelper.php:96:38: UndefinedMethod: Method OCA\Circles\CirclesManager::probeCircles does not exist (see https://psalm.dev/022)
} catch (RequestBuilderException|
FederatedItemException $e) {
throw new NotPermittedException($e->getMessage(), 0, $e);
Expand Down Expand Up @@ -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();

Check failure on line 155 in lib/Service/CircleHelper.php

View workflow job for this annotation

GitHub Actions / static-psalm-analysis

UndefinedMethod

lib/Service/CircleHelper.php:155:38: UndefinedMethod: Method OCA\Circles\CirclesManager::probeCircles does not exist (see https://psalm.dev/022)
} catch (InitiatorNotFoundException|RequestBuilderException $e) {
throw new NotPermittedException($e->getMessage(), 0, $e);
}
Expand Down
9 changes: 5 additions & 4 deletions lib/Service/CollectiveHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit af039a3

Please sign in to comment.