Skip to content

Commit

Permalink
[Community] fixes performances issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Elorfin committed Aug 4, 2023
1 parent 327fe93 commit 464fef8
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/main/community/Finder/RoleFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ public static function getClass(): string

public function configureQueryBuilder(QueryBuilder $qb, array $searches = [], array $sortBy = null): QueryBuilder
{
$isAdmin = false;
if ($this->tokenStorage->getToken()) {
$isAdmin = $this->authChecker->isGranted('ROLE_ADMIN');
} else {
$isAdmin = true;
}

// if not admin, don't list platform_admin role, for security purpose
Expand Down Expand Up @@ -74,14 +73,17 @@ public function configureQueryBuilder(QueryBuilder $qb, array $searches = [], ar
break;
case 'user':
case 'users':
$qb->leftJoin('obj.users', 'ru');
if (!$groupJoin) {
$qb->leftJoin('obj.groups', 'g');
$groupJoin = true;
}
$qb->leftJoin('g.users', 'gu');
$qb->leftJoin('obj.users', 'ru', 'WITH', 'ru.uuid IN (:userIds)');

$qb->andWhere('(ru IS NOT NULL OR EXISTS (
SELECT u2.id
FROM Claroline\CoreBundle\Entity\User AS u2
JOIN u2.groups AS g2
JOIN g2.roles AS r2
WHERE u2.uuid IN (:userIds)
AND r2.id = obj.id
))');

$qb->andWhere('(ru.uuid IN (:userIds) OR gu.uuid IN (:userIds))');
$qb->setParameter('userIds', is_array($filterValue) ? $filterValue : [$filterValue]);
break;
case 'group':
Expand Down

0 comments on commit 464fef8

Please sign in to comment.