Refactor AccompanyingPeriod::getNextCalendarForPerson to enhance performance

This commit is contained in:
Julien Fastré 2024-06-13 18:02:48 +02:00
parent bca0d04201
commit 3e4495dd6e
Signed by: julienfastre
GPG Key ID: BDE2190974723FCB

View File

@ -869,19 +869,24 @@ class AccompanyingPeriod implements
public function getNextCalendarsForPerson(Person $person, $limit = 5): ReadableCollection
{
$today = new \DateTimeImmutable('today');
$criteria = Criteria::create()
->where(Criteria::expr()->gte('startDate', $today))
// ->andWhere(Criteria::expr()->memberOf('persons', $person))
->orderBy(['startDate' => 'DESC'])
->setMaxResults($limit * 2);
return $this->calendars->matching($criteria)
->matching(
// due to a bug, filter two times
Criteria::create()
->where(Criteria::expr()->memberOf('persons', $person))
->setMaxResults($limit)
);
$criteria = Criteria::create();
$expr = Criteria::expr();
$criteria
->where(
$expr->gte('startDate', $today),
)
->orderBy(['startDate' => 'ASC']);
$criteriaByPerson = Criteria::create();
$criteriaByPerson
->where(
$expr->memberOf('persons', $person)
)
->setMaxResults($limit);
return $this->calendars->matching($criteria)->matching($criteriaByPerson);
}
/**