mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Refactor AccompanyingPeriod::getNextCalendarForPerson to enhance performance
This commit is contained in:
parent
bca0d04201
commit
3e4495dd6e
@ -869,19 +869,24 @@ class AccompanyingPeriod implements
|
|||||||
public function getNextCalendarsForPerson(Person $person, $limit = 5): ReadableCollection
|
public function getNextCalendarsForPerson(Person $person, $limit = 5): ReadableCollection
|
||||||
{
|
{
|
||||||
$today = new \DateTimeImmutable('today');
|
$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)
|
$criteria = Criteria::create();
|
||||||
->matching(
|
$expr = Criteria::expr();
|
||||||
// due to a bug, filter two times
|
|
||||||
Criteria::create()
|
$criteria
|
||||||
->where(Criteria::expr()->memberOf('persons', $person))
|
->where(
|
||||||
->setMaxResults($limit)
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user