-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
IBX-7149: Refactored content type-based indexing to rely on a dedicat…
…ed strategy (#296) For more details see https://issues.ibexa.co/browse/IBX-7149 and #296 Key changes: * Fixed fetching batches of content IDs by a content type * Extracted content ID by content type fetching as a strategy * Introduced ContentIdBatchList result for ContentIdListGeneratorStrategy * Fixed ContentList iterator type hinting * [Tests] Aligned ContentFilteringTest after ContentList type hinting fix * [Tests] Added coverage for ContentType input generator strategy * [Tests] Added coverage for ContentIdBatchList result wrapper object --------- Co-authored-by: Andrew Longosz <[email protected]> Co-authored-by: Paweł Niedzielski <[email protected]>
- Loading branch information
1 parent
40b0fd0
commit 1fd57b2
Showing
12 changed files
with
433 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/bundle/Core/Command/Indexer/ContentIdList/ContentTypeInputGeneratorStrategy.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\Core\Command\Indexer\ContentIdList; | ||
|
||
use Generator; | ||
use Ibexa\Bundle\Core\Command\Indexer\ContentIdListGeneratorStrategyInterface; | ||
use Ibexa\Contracts\Core\Repository\ContentService; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\ContentList; | ||
use Ibexa\Contracts\Core\Repository\Values\Content\Query; | ||
use Ibexa\Contracts\Core\Repository\Values\Filter\Filter; | ||
use Ibexa\Core\Search\Indexer\ContentIdBatchList; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class ContentTypeInputGeneratorStrategy implements ContentIdListGeneratorStrategyInterface | ||
{ | ||
private ContentService $contentService; | ||
|
||
public function __construct(ContentService $contentService) | ||
{ | ||
$this->contentService = $contentService; | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException | ||
*/ | ||
public function getBatchList(InputInterface $input, int $batchSize): ContentIdBatchList | ||
{ | ||
$contentList = $this->getContentList($input->getOption('content-type')); | ||
|
||
return new ContentIdBatchList( | ||
$this->buildGenerator($contentList, $batchSize), | ||
$contentList->getTotalCount(), | ||
); | ||
} | ||
|
||
private function buildGenerator(ContentList $contentList, int $batchSize): Generator | ||
{ | ||
$contentIds = []; | ||
foreach ($contentList as $content) { | ||
$contentIds[] = $content->getVersionInfo()->getContentInfo()->getId(); | ||
if (count($contentIds) >= $batchSize) { | ||
yield $contentIds; | ||
$contentIds = []; | ||
} | ||
} | ||
if (!empty($contentIds)) { | ||
yield $contentIds; | ||
} | ||
} | ||
|
||
public function shouldPurgeIndex(InputInterface $input): bool | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
* @throws \Ibexa\Contracts\Core\Repository\Exceptions\BadStateException | ||
*/ | ||
private function getContentList(string $contentTypeIdentifier): ContentList | ||
{ | ||
$filter = new Filter(); | ||
$filter | ||
->withCriterion( | ||
new Query\Criterion\ContentTypeIdentifier($contentTypeIdentifier) | ||
) | ||
; | ||
|
||
return $this->contentService->find($filter); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/bundle/Core/Command/Indexer/ContentIdListGeneratorStrategyInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (C) Ibexa AS. All rights reserved. | ||
* @license For full copyright and license information view LICENSE file distributed with this source code. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Ibexa\Bundle\Core\Command\Indexer; | ||
|
||
use Ibexa\Core\Search\Indexer\ContentIdBatchList; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
interface ContentIdListGeneratorStrategyInterface | ||
{ | ||
public function shouldPurgeIndex(InputInterface $input): bool; | ||
|
||
public function getBatchList(InputInterface $input, int $batchSize): ContentIdBatchList; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.