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

Optimize polls loading #3692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Optimize polls loading #3692

wants to merge 1 commit into from

Conversation

dartcafe
Copy link
Collaborator

@dartcafe dartcafe commented Sep 4, 2024

MigrateSubQueries to joins to avoid heavy subqueries
Hopefully fixes #3688

Migrate

  • PollMapper::subQueryVotesCount
  • PollMapper::subQueryOrphanedVotesCount

Copy link
Contributor

@come-nc come-nc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, should help with performance 👍
Ideally should be tested with OCI, not sure if you’re willing to add https://github.com/nextcloud/.github/blob/master/workflow-templates/phpunit-oci.yml to the workflows? Is can be slow, but oracle database differs on some things so for stuff like a manually written function like that it helps to test on it.

$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()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
\OC::$server->getLogger()->error(json_encode($qb->getSQL()));
\OCP\Server::get(\Psr\Log\LoggerInterface::class)->error(json_encode($qb->getSQL()));

\OC::$server and getLogger are deprecated.
That said I know realise this one is left over debug and will be removed before merge.

Copy link
Collaborator Author

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.

/**
* Subquery for votes count
*/
protected function joinVotesCount(IQueryBuilder &$qb, string $fromAlias, IParameter $currentUserId, ?IParameter $answerFilter = null): IQueryBuilder {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected function joinVotesCount(IQueryBuilder &$qb, string $fromAlias, IParameter $currentUserId, ?IParameter $answerFilter = null): IQueryBuilder {
protected function joinVotesCount(IQueryBuilder $qb, string $fromAlias, IParameter $currentUserId, ?IParameter $answerFilter = null): IQueryBuilder {

You only need a reference if you intend to replace the object with another one ($qb = xxx).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

@dartcafe
Copy link
Collaborator Author

dartcafe commented Sep 10, 2024

Nice, should help with performance 👍

I hope so. But I did not have the chance to test, if the outcome is the same as with the subquery.

But it is just at half way, since I plan to replace the other subquery, too. But it's a pain, since the complexity gets risen by every join; and more error-prone

Ideally should be tested with OCI, not sure if you’re willing to add https://github.com/nextcloud/.github/blob/master/workflow-templates/phpunit-oci.yml to the workflows?

Ah nice. I never thought about testing against OCI, although I have in mind, that this is a real use case.

Is can be slow, but oracle database differs on some things so for stuff like a manually written function like that it helps to test on it.

Yes definitely worth it. I would say, we should add it to the databases.

@dartcafe
Copy link
Collaborator Author

If only someone could take care of the the test suite. 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Optimize polls list loading time
2 participants