fix: reduce number of database queries caused by voter
This commit is contained in:
@@ -464,6 +464,19 @@ class Assignment implements BlameableEntityInterface, TimestampableEntityInterfa
|
|||||||
return $this;
|
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
|
public function getValidDispositions(): Collection
|
||||||
{
|
{
|
||||||
return $this->dispositions->filter(function (Disposition $disposition) {
|
return $this->dispositions->filter(function (Disposition $disposition) {
|
||||||
|
|||||||
@@ -87,6 +87,13 @@ class AssignmentRepository extends ServiceEntityRepository
|
|||||||
->setParameter('now', new \DateTimeImmutable())
|
->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);
|
$this->applyFilterSettings($filterDto, $qb);
|
||||||
|
|
||||||
return $qb->getQuery();
|
return $qb->getQuery();
|
||||||
@@ -280,6 +287,13 @@ class AssignmentRepository extends ServiceEntityRepository
|
|||||||
->setParameter('dateFrom', new \DateTimeImmutable())
|
->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
|
return $qb
|
||||||
->orderBy('assignment.createdAt', 'DESC')
|
->orderBy('assignment.createdAt', 'DESC')
|
||||||
->setMaxResults($limit)
|
->setMaxResults($limit)
|
||||||
|
|||||||
@@ -97,8 +97,9 @@ class DispositionRepository extends ServiceEntityRepository
|
|||||||
$qb = $this->createQueryBuilder('disposition');
|
$qb = $this->createQueryBuilder('disposition');
|
||||||
|
|
||||||
return $qb
|
return $qb
|
||||||
->select('disposition', 'teamer', 'feedback')
|
->select('disposition', 'teamer', 'user', 'feedback')
|
||||||
->innerJoin('disposition.teamer', 'teamer')
|
->innerJoin('disposition.teamer', 'teamer')
|
||||||
|
->leftJoin('teamer.user', 'user')
|
||||||
->leftJoin('teamer.feedback', 'feedback')
|
->leftJoin('teamer.feedback', 'feedback')
|
||||||
->where($qb->expr()->eq('disposition.assignment', ':assignment'))
|
->where($qb->expr()->eq('disposition.assignment', ':assignment'))
|
||||||
->setParameter('assignment', $assignment)
|
->setParameter('assignment', $assignment)
|
||||||
|
|||||||
@@ -74,13 +74,7 @@ class AssignmentVoter extends Voter
|
|||||||
// Only allow applications on empty slots
|
// Only allow applications on empty slots
|
||||||
$availableSlots = (int) $assignment->getAvailableDispositions();
|
$availableSlots = (int) $assignment->getAvailableDispositions();
|
||||||
if (0 < $availableSlots) {
|
if (0 < $availableSlots) {
|
||||||
$dispositions = $this
|
return $assignment->getDispositions()->count() < $availableSlots;
|
||||||
->entityManager
|
|
||||||
->getRepository(Disposition::class)
|
|
||||||
->findCurrentDispositionsByAssignment($assignment)
|
|
||||||
;
|
|
||||||
|
|
||||||
return count($dispositions) < $availableSlots;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only teamers without existing applications may apply to the assignment
|
// Only teamers without existing applications may apply to the assignment
|
||||||
|
|||||||
@@ -57,8 +57,9 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
{% if assignment.applications|length %}
|
{% set application = assignment.applications.first %}
|
||||||
{% set application = assignment.applicationByTeamer(teamer) %}
|
{% set disposition = assignment.dispositions.first%}
|
||||||
|
{% if application %}
|
||||||
{% if application.status == constant('App\\Entity\\Application::STATUS_REJECTED') %}
|
{% if application.status == constant('App\\Entity\\Application::STATUS_REJECTED') %}
|
||||||
<a href="{{ path('app_teamer_assignment_detail', { 'uuid': assignment.uuid, 'r': return_url() }) }}"
|
<a href="{{ path('app_teamer_assignment_detail', { 'uuid': assignment.uuid, 'r': return_url() }) }}"
|
||||||
class="btn btn--small flex items-center space-x-2 bg-gray-100 text-gray-800 hover:bg-gray-50">
|
class="btn btn--small flex items-center space-x-2 bg-gray-100 text-gray-800 hover:bg-gray-50">
|
||||||
@@ -72,8 +73,8 @@
|
|||||||
<span>in Bearbeitung</span>
|
<span>in Bearbeitung</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% elseif assignment.dispositions|length %}
|
{% elseif disposition %}
|
||||||
<a href="{{ path('app_teamer_disposition_detail', { 'uuid': assignment.dispositions[0].uuid }) }}"
|
<a href="{{ path('app_teamer_disposition_detail', { 'uuid': disposition.uuid }) }}"
|
||||||
class="btn btn--small flex items-center space-x-2 bg-green-100 text-green-700 hover:bg-green-50">
|
class="btn btn--small flex items-center space-x-2 bg-green-100 text-green-700 hover:bg-green-50">
|
||||||
{{ icon('check', 'w-4 h-4 shrink-0') }}
|
{{ icon('check', 'w-4 h-4 shrink-0') }}
|
||||||
<span>eingeteilt</span>
|
<span>eingeteilt</span>
|
||||||
|
|||||||
Reference in New Issue
Block a user