DX: improve performance for counting feature linked to person

This commit is contained in:
2023-02-28 17:22:54 +01:00
parent 77c545344c
commit dbcc425f5f
4 changed files with 43 additions and 7 deletions

View File

@@ -32,6 +32,16 @@ class ResidentialAddressRepository extends ServiceEntityRepository
parent::__construct($registry, ResidentialAddress::class);
}
public function countByPerson(Person $person): int
{
return $this->createQueryBuilder('ra')
->select('COUNT(ra)')
->where('ra.person = :person')
->setParameter('person', $person)
->getQuery()
->getSingleScalarResult();
}
public function buildQueryFindCurrentResidentialAddresses(Person $person, ?DateTimeImmutable $at = null): QueryBuilder
{
$date = null === $at ? new DateTimeImmutable('today') : $at;