-
Notifications
You must be signed in to change notification settings - Fork 73
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
Optimize polls loading #3692
base: master
Are you sure you want to change the base?
Optimize polls loading #3692
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -188,13 +188,17 @@ | |||||
$paramUser = $qb->createNamedParameter($currentUserId, IQueryBuilder::PARAM_STR); | ||||||
$paramAnswerYes = $qb->createNamedParameter(Vote::VOTE_YES, IQueryBuilder::PARAM_STR); | ||||||
|
||||||
$qb->selectAlias($qb->createFunction('(' . $this->subQueryVotesCount(self::TABLE, $paramUser)->getSQL() . ')'), 'current_user_count_votes'); | ||||||
$qb->selectAlias($qb->createFunction('(' . $this->subQueryVotesCount(self::TABLE, $paramUser, $paramAnswerYes)->getSQL() . ')'), 'current_user_count_votes_yes'); | ||||||
// migrated to joinVotesCount | ||||||
// $qb->selectAlias($qb->createFunction('(' . $this->subQueryVotesCount(self::TABLE, $paramUser)->getSQL() . ')'), 'current_user_count_votes'); | ||||||
// $qb->selectAlias($qb->createFunction('(' . $this->subQueryVotesCount(self::TABLE, $paramUser, $paramAnswerYes)->getSQL() . ')'), 'current_user_count_votes_yes'); | ||||||
$this->joinVotesCount($qb, self::TABLE, $paramUser, $paramAnswerYes); | ||||||
|
||||||
$qb->selectAlias($qb->createFunction('(' . $this->subQueryOrphanedVotesCount(self::TABLE, $paramUser)->getSQL() . ')'), 'current_user_count_orphaned_votes'); | ||||||
|
||||||
$this->joinOptionsForMaxDate($qb, self::TABLE); | ||||||
$this->joinUserRole($qb, self::TABLE, $currentUserId); | ||||||
$this->joinGroupShares($qb, self::TABLE); | ||||||
\OC::$server->getLogger()->error(json_encode($qb->getSQL())); | ||||||
return $qb; | ||||||
} | ||||||
|
||||||
|
@@ -290,6 +294,30 @@ | |||||
} | ||||||
|
||||||
|
||||||
/** | ||||||
* Subquery for votes count | ||||||
*/ | ||||||
protected function joinVotesCount(IQueryBuilder &$qb, string $fromAlias, IParameter $currentUserId, ?IParameter $answerFilter = null): IQueryBuilder { | ||||||
Check failure on line 300 in lib/Db/PollMapper.php GitHub Actions / Psalm (stable27, 8.1)PossiblyUnusedParam
Check failure on line 300 in lib/Db/PollMapper.php GitHub Actions / Psalm (stable27, 8.1)PossiblyUnusedReturnValue
Check failure on line 300 in lib/Db/PollMapper.php GitHub Actions / Psalm (master, 8.1)PossiblyUnusedParam
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
You only need a reference if you intend to replace the object with another one ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, right. But I would say for consistency the return should be removed, since all joins here base on references. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But even the joins do not require the parameter to be a reference. |
||||||
$joinAlias = 'user_vote_sub'; | ||||||
|
||||||
$qb->selectAlias($qb->func()->count($joinAlias . '.vote_answer'), 'current_user_count_votes'); | ||||||
|
||||||
$qb->selectAlias($qb->func()->sum( | ||||||
$qb->createFunction('CASE WHEN '. $joinAlias . '.vote_answer = \'yes\' THEN 1 ELSE 0 END') | ||||||
), 'current_user_count_votes_yes'); | ||||||
|
||||||
$qb->leftJoin( | ||||||
$fromAlias, | ||||||
Vote::TABLE, | ||||||
$joinAlias, | ||||||
$qb->expr()->andX( | ||||||
$qb->expr()->eq($joinAlias . '.poll_id', $fromAlias . '.id'), | ||||||
$qb->expr()->eq($joinAlias . '.user_id', $currentUserId), | ||||||
) | ||||||
); | ||||||
|
||||||
return $qb; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Subquery for votes count | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
\OC::$server
andgetLogger
are deprecated.That said I know realise this one is left over debug and will be removed before merge.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hehe. Yeah, I know. Thats just an old macro I use for quick logging of implementation steps. Should not have made it into the repo.