From 729b10e5df9e01df009e1782726f1042a3aea6b9 Mon Sep 17 00:00:00 2001 From: Maxence Lange Date: Wed, 2 Oct 2019 15:40:38 -0100 Subject: [PATCH] count only 'Follow' Signed-off-by: Maxence Lange --- lib/Db/FollowsRequest.php | 10 ++++++---- lib/Db/FollowsRequestBuilder.php | 6 +++--- lib/Service/AccountService.php | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/Db/FollowsRequest.php b/lib/Db/FollowsRequest.php index cf2b19d3..ec46401f 100644 --- a/lib/Db/FollowsRequest.php +++ b/lib/Db/FollowsRequest.php @@ -169,8 +169,9 @@ class FollowsRequest extends FollowsRequestBuilder { */ public function countFollowers(string $actorId): int { $qb = $this->countFollowsSelectSql(); - $this->limitToObjectId($qb, $actorId); - $this->limitToAccepted($qb, true); + $qb->limitToObjectId($actorId); + $qb->limitToType(Follow::TYPE); + $qb->limitToAccepted(true); $cursor = $qb->execute(); $data = $cursor->fetch(); @@ -187,8 +188,9 @@ class FollowsRequest extends FollowsRequestBuilder { */ public function countFollowing(string $actorId): int { $qb = $this->countFollowsSelectSql(); - $this->limitToActorId($qb, $actorId); - $this->limitToAccepted($qb, true); + $qb->limitToActorId($actorId); + $qb->limitToType(Follow::TYPE); + $qb->limitToAccepted(true); $cursor = $qb->execute(); $data = $cursor->fetch(); diff --git a/lib/Db/FollowsRequestBuilder.php b/lib/Db/FollowsRequestBuilder.php index a41e7114..550dd278 100644 --- a/lib/Db/FollowsRequestBuilder.php +++ b/lib/Db/FollowsRequestBuilder.php @@ -97,10 +97,10 @@ class FollowsRequestBuilder extends CoreRequestBuilder { /** * Base of the Sql Select request for Shares * - * @return IQueryBuilder + * @return SocialQueryBuilder */ - protected function countFollowsSelectSql(): IQueryBuilder { - $qb = $this->dbConnection->getQueryBuilder(); + protected function countFollowsSelectSql(): SocialQueryBuilder { + $qb = $this->getQueryBuilder(); $qb->selectAlias($qb->createFunction('COUNT(*)'), 'count') ->from(self::TABLE_FOLLOWS, 'f'); diff --git a/lib/Service/AccountService.php b/lib/Service/AccountService.php index 94b7bce0..70ce2714 100644 --- a/lib/Service/AccountService.php +++ b/lib/Service/AccountService.php @@ -284,8 +284,8 @@ class AccountService { */ public function addLocalActorDetailCount(Person &$actor) { $count = [ - 'followers' => $this->followsRequest->countFollowers($actor->getId()) - 1, - 'following' => $this->followsRequest->countFollowing($actor->getId()) - 1, + 'followers' => $this->followsRequest->countFollowers($actor->getId()), + 'following' => $this->followsRequest->countFollowing($actor->getId()), 'post' => $this->streamRequest->countNotesFromActorId($actor->getId()) ]; $actor->setDetailArray('count', $count);