fix: reduce number of database queries caused by voter
This commit is contained in:
@@ -91,4 +91,4 @@ class IndexController extends AbstractController
|
||||
|
||||
return $dispositions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,6 +464,19 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDispositionByTeamer(Teamer $teamer): ?Disposition
|
||||
{
|
||||
$dispositions = $this->dispositions->filter(function (Disposition $disposition) use ($teamer) {
|
||||
return $disposition->getTeamer() === $teamer;
|
||||
});
|
||||
|
||||
if (0 === count($dispositions)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $dispositions->first();
|
||||
}
|
||||
|
||||
public function getValidDispositions(): Collection
|
||||
{
|
||||
return $this->dispositions->filter(function (Disposition $disposition) {
|
||||
|
||||
@@ -87,6 +87,13 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
->setParameter('now', new \DateTimeImmutable())
|
||||
;
|
||||
|
||||
if (0 === $teamer->getTrainingAttendances()->count() && 0 === $teamer->getLicenses()->count()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredLicenses'), 0))
|
||||
->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredTrainings'), 0))
|
||||
;
|
||||
}
|
||||
|
||||
$this->applyFilterSettings($filterDto, $qb);
|
||||
|
||||
return $qb->getQuery();
|
||||
@@ -280,6 +287,13 @@ class AssignmentRepository extends ServiceEntityRepository
|
||||
->setParameter('dateFrom', new \DateTimeImmutable())
|
||||
;
|
||||
|
||||
if (0 === $teamer->getTrainingAttendances()->count() && 0 === $teamer->getLicenses()->count()) {
|
||||
$qb
|
||||
->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredLicenses'), 0))
|
||||
->andWhere($qb->expr()->eq($qb->expr()->count('job_profile.requiredTrainings'), 0))
|
||||
;
|
||||
}
|
||||
|
||||
return $qb
|
||||
->orderBy('assignment.createdAt', 'DESC')
|
||||
->setMaxResults($limit)
|
||||
|
||||
@@ -97,8 +97,9 @@ class DispositionRepository extends ServiceEntityRepository
|
||||
$qb = $this->createQueryBuilder('disposition');
|
||||
|
||||
return $qb
|
||||
->select('disposition', 'teamer', 'feedback')
|
||||
->select('disposition', 'teamer', 'user', 'feedback')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->leftJoin('teamer.user', 'user')
|
||||
->leftJoin('teamer.feedback', 'feedback')
|
||||
->where($qb->expr()->eq('disposition.assignment', ':assignment'))
|
||||
->setParameter('assignment', $assignment)
|
||||
|
||||
@@ -74,13 +74,7 @@ class AssignmentVoter extends Voter
|
||||
// Only allow applications on empty slots
|
||||
$availableSlots = (int) $assignment->getAvailableDispositions();
|
||||
if (0 < $availableSlots) {
|
||||
$dispositions = $this
|
||||
->entityManager
|
||||
->getRepository(Disposition::class)
|
||||
->findCurrentDispositionsByAssignment($assignment)
|
||||
;
|
||||
|
||||
return count($dispositions) < $availableSlots;
|
||||
return $assignment->getDispositions()->count() < $availableSlots;
|
||||
}
|
||||
|
||||
// Only teamers without existing applications may apply to the assignment
|
||||
@@ -98,4 +92,4 @@ class AssignmentVoter extends Voter
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user