diff --git a/eZ/Publish/API/Repository/ContentService.php b/eZ/Publish/API/Repository/ContentService.php index ead453871a..e13d4451ad 100644 --- a/eZ/Publish/API/Repository/ContentService.php +++ b/eZ/Publish/API/Repository/ContentService.php @@ -588,6 +588,8 @@ public function find(Filter $filter, ?array $languages = null): ContentList; * @param string[] $languages a list of language codes to be added as additional constraints. * If skipped, by default, unless SiteAccessAware layer has been disabled, languages set * for a SiteAccess in a current context will be used. + * @param int|null $limit If set, the count will be limited to first $limit items found. + * In some cases it can significantly speed up a count operation for more complex filters. */ - public function count(Filter $filter, ?array $languages = null): int; + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int; } diff --git a/eZ/Publish/API/Repository/LocationService.php b/eZ/Publish/API/Repository/LocationService.php index e8af6dbc4b..750ce4838f 100644 --- a/eZ/Publish/API/Repository/LocationService.php +++ b/eZ/Publish/API/Repository/LocationService.php @@ -127,14 +127,17 @@ public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, ?ar * * @return int */ - public function getLocationChildCount(Location $location): int; + public function getLocationChildCount(Location $location, ?int $limit = null): int; /** * Return the subtree size of a given location. * * Warning! This method is not permission aware by design. + * + * @param \eZ\Publish\API\Repository\Values\Content\Location $location + * @param int|null $limit Optional limit to the number of locations to count. (Can be used to limit the number of locations counted in large subtrees.) */ - public function getSubtreeSize(Location $location): int; + public function getSubtreeSize(Location $location, ?int $limit = null): int; /** * Creates the new $location in the content repository for the given content. @@ -275,6 +278,8 @@ public function find(Filter $filter, ?array $languages = null): LocationList; * @param string[] $languages a list of language codes to be added as additional constraints. * If skipped, by default, unless SiteAccessAware layer has been disabled, languages set * for a SiteAccess in a current context will be used. + * @param int|null $limit If set, the count will be limited to first $limit items found. + * In some cases it can significantly speed up a count operation for more complex filters. */ - public function count(Filter $filter, ?array $languages = null): int; + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int; } diff --git a/eZ/Publish/API/Repository/Tests/LocationServiceTest.php b/eZ/Publish/API/Repository/Tests/LocationServiceTest.php index 153f768ba7..7979aa482b 100644 --- a/eZ/Publish/API/Repository/Tests/LocationServiceTest.php +++ b/eZ/Publish/API/Repository/Tests/LocationServiceTest.php @@ -1114,6 +1114,26 @@ public function testGetLocationChildCount() ); } + /** + * Test for the getLocationChildCount() method with a limitation on the number of children. + * + * @see \eZ\Publish\API\Repository\LocationService::getLocationChildCount() + * @depends eZ\Publish\API\Repository\Tests\LocationServiceTest::testLoadLocation + */ + public function testGetLocationChildCountWithLimitation() + { + // $locationId is the ID of an existing location + $locationService = $this->getRepository()->getLocationService(); + + $this->assertSame( + 2, + $locationService->getLocationChildCount( + $locationService->loadLocation($this->generateId('location', 5)), + 2 + ) + ); + } + /** * Test for the loadLocationChildren() method. * @@ -3552,6 +3572,42 @@ public function testGetSubtreeSize(): Location return $location; } + public function testGetSubtreeSizeWithLimit(): Location + { + $repository = $this->getRepository(); + $locationService = $repository->getLocationService(); + + $folder = $this->createFolder(['eng-GB' => 'Parent Folder'], 2); + $location = $folder->getVersionInfo()->getContentInfo()->getMainLocation(); + self::assertSame(1, $locationService->getSubtreeSize($location)); + + for ($i = 1; $i <= 10; ++$i) { + $this->createFolder(['eng-GB' => 'Child ' . $i], $location->id); + } + + self::assertSame(3, $locationService->getSubtreeSize($location, 3)); + + return $location; + } + + public function testGetSubtreeSizeWithInvalidLimitHasNoEffect(): Location + { + $repository = $this->getRepository(); + $locationService = $repository->getLocationService(); + + $folder = $this->createFolder(['eng-GB' => 'Parent Folder'], 2); + $location = $folder->getVersionInfo()->getContentInfo()->getMainLocation(); + self::assertSame(1, $locationService->getSubtreeSize($location)); + + for ($i = 1; $i <= 10; ++$i) { + $this->createFolder(['eng-GB' => 'Child ' . $i], $location->id); + } + + self::assertSame(11, $locationService->getSubtreeSize($location, -2)); + + return $location; + } + /** * Loads properties from all locations in the $location's subtree. * diff --git a/eZ/Publish/Core/Persistence/Cache/LocationHandler.php b/eZ/Publish/Core/Persistence/Cache/LocationHandler.php index d34c03d3b0..d1f7686a4f 100644 --- a/eZ/Publish/Core/Persistence/Cache/LocationHandler.php +++ b/eZ/Publish/Core/Persistence/Cache/LocationHandler.php @@ -259,13 +259,13 @@ public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null) return $this->persistenceHandler->locationHandler()->copySubtree($sourceId, $destinationParentId, $newOwnerId); } - public function getSubtreeSize(string $path): int + public function getSubtreeSize(string $path, ?int $limit = null): int { $this->logger->logCall(__METHOD__, [ 'path' => $path, ]); - return $this->persistenceHandler->locationHandler()->getSubtreeSize($path); + return $this->persistenceHandler->locationHandler()->getSubtreeSize($path, $limit); } /** diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway.php b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway.php index d49a1f0286..a3a0e70e42 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway.php @@ -111,7 +111,7 @@ abstract public function loadParentLocationsDataForDraftContent(int $contentId): */ abstract public function getSubtreeContent(int $sourceId, bool $onlyIds = false): array; - abstract public function getSubtreeSize(string $path): int; + abstract public function getSubtreeSize(string $path, ?int $limit = null): int; /** * Returns data for the first level children of the location identified by given $locationId. diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php index 495947b5fa..b1617fe565 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/DoctrineDatabase.php @@ -16,6 +16,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use eZ\Publish\Core\Persistence\Legacy\Content\Language\MaskGenerator; use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway; +use eZ\Publish\Core\Persistence\Legacy\Traits\Doctrine\LimitedCountQueryTrait; use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\CriteriaConverter; use eZ\Publish\Core\Search\Legacy\Content\Common\Gateway\SortClauseConverter; use eZ\Publish\SPI\Persistence\Content\ContentInfo; @@ -35,6 +36,8 @@ */ final class DoctrineDatabase extends Gateway { + use LimitedCountQueryTrait; + /** @var \Doctrine\DBAL\Connection */ private $connection; @@ -237,7 +240,7 @@ public function getSubtreeContent(int $sourceId, bool $onlyIds = false): array : $results; } - public function getSubtreeSize(string $path): int + public function getSubtreeSize(string $path, ?int $limit = null): int { $query = $this->createNodeQueryBuilder([$this->dbPlatform->getCountExpression('node_id')]); $query->andWhere( @@ -245,10 +248,16 @@ public function getSubtreeSize(string $path): int 't.path_string', $query->createPositionalParameter( $path . '%', - ) + ), ) ); + $query = $this->wrapCountQuery( + $query, + 't.node_id', + $limit + ); + return (int) $query->execute()->fetchOne(); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php index ed1acf56e2..57c90007c3 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Gateway/ExceptionConversion.php @@ -106,10 +106,10 @@ public function getSubtreeContent(int $sourceId, bool $onlyIds = false): array } } - public function getSubtreeSize(string $path): int + public function getSubtreeSize(string $path, ?int $limit = null): int { try { - return $this->innerGateway->getSubtreeSize($path); + return $this->innerGateway->getSubtreeSize($path, $limit); } catch (DBALException | PDOException $e) { throw DatabaseException::wrap($e); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Handler.php b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Handler.php index b125238675..93f51964a1 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Content/Location/Handler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Content/Location/Handler.php @@ -346,9 +346,9 @@ public function copySubtree($sourceId, $destinationParentId, $newOwnerId = null) return $copiedSubtreeRootLocation; } - public function getSubtreeSize(string $path): int + public function getSubtreeSize(string $path, ?int $limit = null): int { - return $this->locationGateway->getSubtreeSize($path); + return $this->locationGateway->getSubtreeSize($path, $limit); } /** diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php b/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php index 0cef49854a..2855cf87df 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Content/Doctrine/DoctrineGateway.php @@ -18,6 +18,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use eZ\Publish\Core\Persistence\Legacy\Filter\Gateway\Gateway; +use eZ\Publish\Core\Persistence\Legacy\Traits\Doctrine\LimitedCountQueryTrait; use eZ\Publish\SPI\Persistence\Filter\CriterionVisitor; use eZ\Publish\SPI\Persistence\Filter\Doctrine\FilteringQueryBuilder; use eZ\Publish\SPI\Persistence\Filter\SortClauseVisitor; @@ -31,6 +32,8 @@ */ final class DoctrineGateway implements Gateway { + use LimitedCountQueryTrait; + public const COLUMN_MAP = [ // Content Info 'content_id' => 'content.id', @@ -87,13 +90,19 @@ private function getDatabasePlatform(): AbstractPlatform } } - public function count(FilteringCriterion $criterion): int + public function count(FilteringCriterion $criterion, ?int $limit = null): int { $query = $this->buildQuery( [$this->getDatabasePlatform()->getCountExpression('DISTINCT content.id')], $criterion ); + $query = $this->wrapCountQuery( + $query, + 'content.id', + $limit + ); + return (int)$query->execute()->fetch(FetchMode::COLUMN); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Gateway.php b/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Gateway.php index ec64507575..92368afabf 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Gateway.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Gateway.php @@ -18,9 +18,9 @@ interface Gateway { /** - * Return number of matched rows for the given Criteria (a total count w/o pagination constraints). + * Return number of matched rows for the given Criteria (a total count w/o pagination constraints unless an upper limit is applied). */ - public function count(FilteringCriterion $criterion): int; + public function count(FilteringCriterion $criterion, ?int $limit = null): int; /** * Return iterator for raw Repository data for the given Query result filtered by the given Criteria, diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php b/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php index 3f545d58d2..b7fe4e3b3c 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/Gateway/Location/Doctrine/DoctrineGateway.php @@ -16,6 +16,7 @@ use eZ\Publish\Core\Persistence\Legacy\Content\Gateway as ContentGateway; use eZ\Publish\Core\Persistence\Legacy\Content\Location\Gateway as LocationGateway; use eZ\Publish\Core\Persistence\Legacy\Filter\Gateway\Gateway; +use eZ\Publish\Core\Persistence\Legacy\Traits\Doctrine\LimitedCountQueryTrait; use eZ\Publish\SPI\Persistence\Filter\CriterionVisitor; use eZ\Publish\SPI\Persistence\Filter\Doctrine\FilteringQueryBuilder; use eZ\Publish\SPI\Persistence\Filter\SortClauseVisitor; @@ -26,6 +27,8 @@ */ final class DoctrineGateway implements Gateway { + use LimitedCountQueryTrait; + /** @var \Doctrine\DBAL\Connection */ private $connection; @@ -54,12 +57,18 @@ private function getDatabasePlatform(): AbstractPlatform } } - public function count(FilteringCriterion $criterion): int + public function count(FilteringCriterion $criterion, ?int $limit = null): int { $query = $this->buildQuery($criterion); $query->select($this->getDatabasePlatform()->getCountExpression('DISTINCT location.node_id')); + $query = $this->wrapCountQuery( + $query, + 'location.node_id', + $limit + ); + return (int)$query->execute()->fetch(FetchMode::COLUMN); } diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/ContentFilteringHandler.php b/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/ContentFilteringHandler.php index 488b7efdb9..eef6e88c50 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/ContentFilteringHandler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/ContentFilteringHandler.php @@ -73,8 +73,8 @@ function (array $row): ContentItem { return $list; } - public function count(Filter $filter): int + public function count(Filter $filter, ?int $limit = null): int { - return $this->gateway->count($filter->getCriterion()); + return $this->gateway->count($filter->getCriterion(), $limit); } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/LocationFilteringHandler.php b/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/LocationFilteringHandler.php index 7c27e62a16..ff422eeaac 100644 --- a/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/LocationFilteringHandler.php +++ b/eZ/Publish/Core/Persistence/Legacy/Filter/Handler/LocationFilteringHandler.php @@ -69,8 +69,8 @@ function (array $row): LocationWithContentInfo { return $list; } - public function count(Filter $filter): int + public function count(Filter $filter, ?int $limit = null): int { - return $this->gateway->count($filter->getCriterion()); + return $this->gateway->count($filter->getCriterion(), $limit); } } diff --git a/eZ/Publish/Core/Persistence/Legacy/Traits/Doctrine/LimitedCountQueryTrait.php b/eZ/Publish/Core/Persistence/Legacy/Traits/Doctrine/LimitedCountQueryTrait.php new file mode 100644 index 0000000000..8caa3a260c --- /dev/null +++ b/eZ/Publish/Core/Persistence/Legacy/Traits/Doctrine/LimitedCountQueryTrait.php @@ -0,0 +1,56 @@ + 0; + + if (!$useLimit) { + return $queryBuilder; + } + + $querySql = $queryBuilder->select($countableField) + ->setMaxResults($limit) + ->getSQL(); + + $countQuery = $this->connection->createQueryBuilder(); + + return $countQuery + ->select( + $queryBuilder->getConnection()->getDatabasePlatform()->getCountExpression('*') + ) + ->from('(' . $querySql . ')', 'csub') + ->setParameters($queryBuilder->getParameters(), $queryBuilder->getParameterTypes()); + } +} diff --git a/eZ/Publish/Core/Repository/ContentService.php b/eZ/Publish/Core/Repository/ContentService.php index 370bba6c90..d9f3edee9d 100644 --- a/eZ/Publish/Core/Repository/ContentService.php +++ b/eZ/Publish/Core/Repository/ContentService.php @@ -2626,7 +2626,7 @@ public function find(Filter $filter, ?array $languages = null): ContentList return new ContentList($contentItemsIterator->getTotalCount(), $contentItems); } - public function count(Filter $filter, ?array $languages = null): int + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int { $filter = clone $filter; if (!empty($languages)) { @@ -2646,6 +2646,6 @@ public function count(Filter $filter, ?array $languages = null): int $filter->andWithCriterion($permissionCriterion); } - return $this->contentFilteringHandler->count($filter); + return $this->contentFilteringHandler->count($filter, $limit); } } diff --git a/eZ/Publish/Core/Repository/LocationService.php b/eZ/Publish/Core/Repository/LocationService.php index 8fa272dd9c..2b9d4d4af9 100644 --- a/eZ/Publish/Core/Repository/LocationService.php +++ b/eZ/Publish/Core/Repository/LocationService.php @@ -372,17 +372,18 @@ public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, ?ar /** * Returns the number of children which are readable by the current user of a Location object. */ - public function getLocationChildCount(APILocation $location): int + public function getLocationChildCount(APILocation $location, ?int $limit = null): int { $filter = $this->buildLocationChildrenFilter($location); - return $this->count($filter); + return $this->count($filter, null, $limit); } - public function getSubtreeSize(APILocation $location): int + public function getSubtreeSize(APILocation $location, ?int $limit = null): int { return $this->persistenceHandler->locationHandler()->getSubtreeSize( - $location->getPathString() + $location->getPathString(), + $limit ); } @@ -943,7 +944,7 @@ public function find(Filter $filter, ?array $languages = null): LocationList ); } - public function count(Filter $filter, ?array $languages = null): int + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int { $filter = clone $filter; if (!empty($languages)) { @@ -963,7 +964,7 @@ public function count(Filter $filter, ?array $languages = null): int $filter->andWithCriterion($permissionCriterion); } - return $this->locationFilteringHandler->count($filter); + return $this->locationFilteringHandler->count($filter, $limit); } /** diff --git a/eZ/Publish/Core/Repository/SiteAccessAware/ContentService.php b/eZ/Publish/Core/Repository/SiteAccessAware/ContentService.php index 3c76b09317..f8233bc303 100644 --- a/eZ/Publish/Core/Repository/SiteAccessAware/ContentService.php +++ b/eZ/Publish/Core/Repository/SiteAccessAware/ContentService.php @@ -284,11 +284,12 @@ public function find(Filter $filter, ?array $languages = null): ContentList ); } - public function count(Filter $filter, ?array $languages = null): int + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int { return $this->service->count( $filter, - $this->languageResolver->getPrioritizedLanguages($languages) + $this->languageResolver->getPrioritizedLanguages($languages), + $limit ); } } diff --git a/eZ/Publish/Core/Repository/SiteAccessAware/LocationService.php b/eZ/Publish/Core/Repository/SiteAccessAware/LocationService.php index 1a5700d2f1..86f4b83523 100644 --- a/eZ/Publish/Core/Repository/SiteAccessAware/LocationService.php +++ b/eZ/Publish/Core/Repository/SiteAccessAware/LocationService.php @@ -104,14 +104,14 @@ public function loadParentLocationsForDraftContent(VersionInfo $versionInfo, ?ar ); } - public function getLocationChildCount(Location $location): int + public function getLocationChildCount(Location $location, ?int $limit = null ): int { - return $this->service->getLocationChildCount($location); + return $this->service->getLocationChildCount($location, $limit); } - public function getSubtreeSize(Location $location): int + public function getSubtreeSize(Location $location, ?int $limit = null): int { - return $this->service->getSubtreeSize($location); + return $this->service->getSubtreeSize($location, $limit); } public function createLocation(ContentInfo $contentInfo, LocationCreateStruct $locationCreateStruct): Location @@ -192,11 +192,12 @@ public function find(Filter $filter, ?array $languages = null): LocationList ); } - public function count(Filter $filter, ?array $languages = null): int + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int { return $this->service->count( $filter, - $this->languageResolver->getPrioritizedLanguages($languages) + $this->languageResolver->getPrioritizedLanguages($languages), + $limit ); } } diff --git a/eZ/Publish/SPI/Persistence/Content/Location/Handler.php b/eZ/Publish/SPI/Persistence/Content/Location/Handler.php index ff36c20df7..fc69b27adf 100644 --- a/eZ/Publish/SPI/Persistence/Content/Location/Handler.php +++ b/eZ/Publish/SPI/Persistence/Content/Location/Handler.php @@ -110,7 +110,7 @@ public function loadParentLocationsForDraftContent($contentId); */ public function copySubtree($sourceId, $destinationParentId); - public function getSubtreeSize(string $path): int; + public function getSubtreeSize(string $path, ?int $limit = null): int; /** * Moves location identified by $sourceId into new parent identified by $destinationParentId. diff --git a/eZ/Publish/SPI/Persistence/Filter/Content/Handler.php b/eZ/Publish/SPI/Persistence/Filter/Content/Handler.php index 3acd26f354..d03db1cfe9 100644 --- a/eZ/Publish/SPI/Persistence/Filter/Content/Handler.php +++ b/eZ/Publish/SPI/Persistence/Filter/Content/Handler.php @@ -22,5 +22,5 @@ interface Handler */ public function find(Filter $filter): iterable; - public function count(Filter $filter): int; + public function count(Filter $filter, ?int $limit = null): int; } diff --git a/eZ/Publish/SPI/Persistence/Filter/Location/Handler.php b/eZ/Publish/SPI/Persistence/Filter/Location/Handler.php index 84ef9e397e..ae8110dede 100644 --- a/eZ/Publish/SPI/Persistence/Filter/Location/Handler.php +++ b/eZ/Publish/SPI/Persistence/Filter/Location/Handler.php @@ -22,5 +22,5 @@ interface Handler */ public function find(Filter $filter): iterable; - public function count(Filter $filter): int; + public function count(Filter $filter, ?int $limit = null): int; } diff --git a/eZ/Publish/SPI/Repository/Decorator/ContentServiceDecorator.php b/eZ/Publish/SPI/Repository/Decorator/ContentServiceDecorator.php index e45b5038be..27504fe6f6 100644 --- a/eZ/Publish/SPI/Repository/Decorator/ContentServiceDecorator.php +++ b/eZ/Publish/SPI/Repository/Decorator/ContentServiceDecorator.php @@ -276,8 +276,8 @@ public function find(Filter $filter, ?array $languages = null): ContentList return $this->innerService->find($filter, $languages); } - public function count(Filter $filter, ?array $languages = null): int + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int { - return $this->innerService->count($filter, $languages); + return $this->innerService->count($filter, $languages, $limit); } } diff --git a/eZ/Publish/SPI/Repository/Decorator/LocationServiceDecorator.php b/eZ/Publish/SPI/Repository/Decorator/LocationServiceDecorator.php index 31885e27b9..276147a778 100644 --- a/eZ/Publish/SPI/Repository/Decorator/LocationServiceDecorator.php +++ b/eZ/Publish/SPI/Repository/Decorator/LocationServiceDecorator.php @@ -82,14 +82,14 @@ public function loadParentLocationsForDraftContent( return $this->innerService->loadParentLocationsForDraftContent($versionInfo, $prioritizedLanguages); } - public function getLocationChildCount(Location $location): int + public function getLocationChildCount(Location $location, ?int $limit = null): int { - return $this->innerService->getLocationChildCount($location); + return $this->innerService->getLocationChildCount($location, $limit); } - public function getSubtreeSize(Location $location): int + public function getSubtreeSize(Location $location, ?int $limit = null): int { - return $this->innerService->getSubtreeSize($location); + return $this->innerService->getSubtreeSize($location, $limit); } public function createLocation( @@ -160,8 +160,8 @@ public function find(Filter $filter, ?array $languages = null): LocationList return $this->innerService->find($filter, $languages); } - public function count(Filter $filter, ?array $languages = null): int + public function count(Filter $filter, ?array $languages = null, ?int $limit = null): int { - return $this->innerService->count($filter, $languages); + return $this->innerService->count($filter, $languages, $limit); } } diff --git a/eZ/Publish/SPI/Repository/Tests/Decorator/LocationServiceDecoratorTest.php b/eZ/Publish/SPI/Repository/Tests/Decorator/LocationServiceDecoratorTest.php index 128fc40758..0b9a3d5259 100644 --- a/eZ/Publish/SPI/Repository/Tests/Decorator/LocationServiceDecoratorTest.php +++ b/eZ/Publish/SPI/Repository/Tests/Decorator/LocationServiceDecoratorTest.php @@ -151,7 +151,7 @@ public function testGetLocationChildCountDecorator() $serviceMock = $this->createServiceMock(); $decoratedService = $this->createDecorator($serviceMock); - $parameters = [$this->createMock(Location::class)]; + $parameters = [$this->createMock(Location::class), 8]; $serviceMock->expects($this->once())->method('getLocationChildCount')->with(...$parameters);