Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable22] only returns population on direct request from the front-end or occ command #886

Merged
merged 1 commit into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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