Skip to content

Commit

Permalink
only returns population on direct request from the front-end or occ c…
Browse files Browse the repository at this point in the history
…ommand

Signed-off-by: Maxence Lange <[email protected]>
  • Loading branch information
ArtificialOwl committed Dec 12, 2021
1 parent 0f103be commit 520031b
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 23 deletions.
4 changes: 3 additions & 1 deletion lib/Command/CirclesList.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\ModelManager;
use OCA\Circles\Model\Probes\BasicProbe;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\ConfigService;
Expand Down Expand Up @@ -190,7 +191,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$probe = new CircleProbe();
$probe->filterHiddenCircles()
->filterBackendCircles();
->filterBackendCircles()
->addDetail(BasicProbe::DETAILS_POPULATION);

if ($input->getOption('system')) {
$probe->includeSystemCircles();
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
use OCA\Circles\Exceptions\SingleCircleNotFoundException;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\BasicProbe;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\ConfigService;
Expand Down Expand Up @@ -270,7 +271,8 @@ public function circles(string $emulated): DataResponse {

$probe = new CircleProbe();
$probe->filterHiddenCircles()
->filterBackendCircles();
->filterBackendCircles()
->addDetail(BasicProbe::DETAILS_POPULATION);

return new DataResponse($this->serializeArray($this->circleService->getCircles($probe)));
} catch (Exception $e) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/LocalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
use OCA\Circles\Exceptions\SingleCircleNotFoundException;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\BasicProbe;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\ConfigService;
Expand Down Expand Up @@ -419,7 +420,8 @@ public function circles(): DataResponse {

$probe = new CircleProbe();
$probe->filterHiddenCircles()
->filterBackendCircles();
->filterBackendCircles()
->addDetail(BasicProbe::DETAILS_POPULATION);

return new DataResponse($this->serializeArray($this->circleService->getCircles($probe)));
} catch (Exception $e) {
Expand Down
4 changes: 3 additions & 1 deletion lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
use OCA\Circles\Model\Federated\RemoteInstance;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\BasicProbe;
use OCA\Circles\Model\Probes\CircleProbe;
use OCA\Circles\Service\CircleService;
use OCA\Circles\Service\ConfigService;
Expand Down Expand Up @@ -267,7 +268,8 @@ public function circles(): DataResponse {

$probe = new CircleProbe();
$probe->setFilterCircle($filterCircle)
->setFilterMember($filterMember);
->setFilterMember($filterMember)
->addDetail(BasicProbe::DETAILS_POPULATION);

$circles = $this->circleService->getCircles($probe);

Expand Down
14 changes: 11 additions & 3 deletions lib/Db/CircleRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
use OCA\Circles\Model\Circle;
use OCA\Circles\Model\FederatedUser;
use OCA\Circles\Model\Member;
use OCA\Circles\Model\Probes\BasicProbe;
use OCA\Circles\Model\Probes\CircleProbe;

/**
Expand Down Expand Up @@ -184,7 +185,10 @@ public function getCircles(?IFederatedUser $initiator, CircleProbe $probe): arra
$qb->limitToRemoteInstance(CoreQueryBuilder::CIRCLE, $probe->getFilterRemoteInstance(), false);
}

$qb->countMembers(CoreQueryBuilder::CIRCLE);
if ($probe->showDetail(BasicProbe::DETAILS_POPULATION)) {
$qb->countMembers(CoreQueryBuilder::CIRCLE);
}

$qb->chunk($probe->getItemsOffset(), $probe->getItemsLimit());

return $this->getItemsFromRequest($qb);
Expand Down Expand Up @@ -258,7 +262,10 @@ public function getCircle(
if ($probe->hasFilterRemoteInstance()) {
$qb->limitToRemoteInstance(CoreQueryBuilder::CIRCLE, $probe->getFilterRemoteInstance(), false);
}
$qb->countMembers(CoreQueryBuilder::CIRCLE);

if ($probe->showDetail(BasicProbe::DETAILS_POPULATION)) {
$qb->countMembers(CoreQueryBuilder::CIRCLE);
}

return $this->getItemFromRequest($qb);
}
Expand Down Expand Up @@ -356,7 +363,8 @@ public function searchCircle(Circle $circle, ?IFederatedUser $initiator = null):

if (!is_null($initiator)) {
$qb->setOptions(
[CoreQueryBuilder::CIRCLE], [
[CoreQueryBuilder::CIRCLE],
[
'getData' => true,
'initiatorDirectMember' => true
]
Expand Down
5 changes: 0 additions & 5 deletions lib/Db/CoreQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,6 @@ public function countMembers(string $alias): void {
return;
}

$getData = $this->getBool('getData', $options, false);
if (!$getData) {
return;
}

$expr = $this->expr();
$this->selectAlias(
$this->createFunction('COUNT(`' . $aliasMemberCount . '`.`member_id`)'),
Expand Down
4 changes: 2 additions & 2 deletions lib/IQueryProbe.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ public function getItemsLimit(): int;
public function getDetails(): int;

/**
* @param int $details
* @param int $detail
*
* @return bool
*/
public function showDetails(int $details): bool;
public function showDetail(int $detail): bool;

/**
* @return Circle
Expand Down
19 changes: 15 additions & 4 deletions lib/Model/Probes/BasicProbe.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
*/
class BasicProbe implements IQueryProbe {
public const DETAILS_NONE = 0;
public const DETAILS_ALL = 64;
public const DETAILS_POPULATION = 32;
public const DETAILS_ALL = 127;


/** @var int */
Expand Down Expand Up @@ -122,14 +123,24 @@ public function getDetails(): int {
return $this->details;
}

/**
* @param int $detail
*
* @return $this
*/
public function addDetail(int $detail): self {
$this->details |= $detail;

return $this;
}

/**
* @param int $details
* @param int $detail
*
* @return bool
*/
public function showDetails(int $details): bool {
return (($this->getDetails() & $details) !== 0);
public function showDetail(int $detail): bool {
return (($this->getDetails() & $detail) !== 0);
}


Expand Down
5 changes: 0 additions & 5 deletions lib/Service/MigrationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,6 @@ private function generateMemberFrom21(SimpleDataStore $data): Member {

$member->setSingleId($singleMember->getSingleId());

// "cached_update":"2021-05-02 12:13:22",
// "joined":"2021-05-02 12:13:22",
// "contact_checked":null,"
// "circle_source":null}

return $member;
}

Expand Down

0 comments on commit 520031b

Please sign in to comment.