diff --git a/CHANGELOG.md b/CHANGELOG.md index 359936a1b..c0992dcfa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to ## Unreleased +* [search] enforce limit of results for fetching rsults by search api https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/576 * [activity] Fix delete button for document (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/554) * [activity] Add return path the document generation (https://gitlab.com/champs-libres/departement-de-la-vendee/accent-suivi-developpement/-/issues/553) * [person] add person ressource to person docgen normaliser (https://gitlab.com/champs-libres/departement-de-la-vendee/chill/-/issues/517) diff --git a/phpstan-types.neon b/phpstan-types.neon index ddde5cc03..9671c05a5 100644 --- a/phpstan-types.neon +++ b/phpstan-types.neon @@ -250,11 +250,6 @@ parameters: count: 1 path: src/Bundle/ChillMainBundle/Entity/Address.php - - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" - count: 1 - path: src/Bundle/ChillMainBundle/Entity/Embeddable/CommentEmbeddable.php - - message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" count: 1 diff --git a/src/Bundle/ChillMainBundle/Search/SearchApi.php b/src/Bundle/ChillMainBundle/Search/SearchApi.php index 7436b3303..5c4026a45 100644 --- a/src/Bundle/ChillMainBundle/Search/SearchApi.php +++ b/src/Bundle/ChillMainBundle/Search/SearchApi.php @@ -11,6 +11,7 @@ declare(strict_types=1); namespace Chill\MainBundle\Search; +use Chill\MainBundle\Pagination\Paginator; use Chill\MainBundle\Pagination\PaginatorFactory; use Chill\MainBundle\Serializer\Model\Collection; use Doctrine\DBAL\Types\Types; @@ -102,9 +103,9 @@ class SearchApi return $items; } - private function buildUnionQuery(array $queries, $types, $parameters) + private function buildUnionQuery(array $queries, $types, $parameters, Paginator $paginator) { - $query = '{unions} ORDER BY pertinence DESC'; + $query = '{unions} ORDER BY pertinence DESC LIMIT ? OFFSET ?'; $unions = []; $parameters = []; @@ -113,6 +114,10 @@ class SearchApi $parameters = array_merge($parameters, $q->buildParameters()); } + // add pagination limit + $parameters[] = $paginator->getItemsPerPage(); + $parameters[] = $paginator->getCurrentPageFirstItemNumber(); + $union = implode(' UNION ', $unions); return [ @@ -132,9 +137,9 @@ class SearchApi return (int) $countNq->getSingleScalarResult(); } - private function fetchRawResult($queries, $types, $parameters, $paginator): array + private function fetchRawResult($queries, $types, $parameters, Paginator $paginator): array { - [$union, $parameters] = $this->buildUnionQuery($queries, $types, $parameters); + [$union, $parameters] = $this->buildUnionQuery($queries, $types, $parameters, $paginator); $rsm = new ResultSetMappingBuilder($this->em); $rsm->addScalarResult('key', 'key', Types::STRING) ->addScalarResult('metadata', 'metadata', Types::JSON) diff --git a/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php b/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php index 357cf38be..e458b049d 100644 --- a/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php +++ b/src/Bundle/ChillPersonBundle/Menu/SectionMenuBuilder.php @@ -13,6 +13,7 @@ namespace Chill\PersonBundle\Menu; use Chill\MainBundle\Routing\LocalMenuBuilderInterface; use Chill\PersonBundle\Security\Authorization\PersonVoter; +use Doctrine\ORM\Query\Parameter; use Knp\Menu\MenuItem; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; @@ -27,6 +28,8 @@ class SectionMenuBuilder implements LocalMenuBuilderInterface protected TranslatorInterface $translator; + protected ParameterBagInterface $parameterBag; + /** * SectionMenuBuilder constructor. */ diff --git a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php index 5f1311ae5..0e146b5c0 100644 --- a/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php +++ b/src/Bundle/ChillPersonBundle/Serializer/Normalizer/PersonDocGenNormalizer.php @@ -116,7 +116,7 @@ class PersonDocGenNormalizer implements 'memo' => $person->getMemo(), 'numberOfChildren' => (string) $person->getNumberOfChildren(), 'address' => $this->normalizer->normalize($person->getCurrentPersonAddress(), $format, $addressContext), - 'resources' => $this->normalizer->normalize($person->getResources(), $format, $personResourceContext), + //'resources' => $this->normalizer->normalize($person->getResources(), $format, $personResourceContext), ]; if ($context['docgen:person:with-household'] ?? false) { @@ -193,7 +193,7 @@ class PersonDocGenNormalizer implements $data = $normalizer->normalize($attributes, $format, $context); - $data['resources'] = []; + //$data['resources'] = []; if ($context['docgen:person:with-relations'] ?? false) { $data['relations'] = [];