-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
225 additions
and
63 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMeilisearchPlugin\DataProvider; | ||
|
||
use Doctrine\Persistence\ManagerRegistry; | ||
use DoctrineBatchUtils\BatchProcessing\SelectBatchIteratorAggregate; | ||
use Psr\EventDispatcher\EventDispatcherInterface; | ||
use Setono\Doctrine\ORMTrait; | ||
use Setono\SyliusMeilisearchPlugin\Config\Index; | ||
use Setono\SyliusMeilisearchPlugin\Event\QueryBuilderForDataProvisionCreated; | ||
|
||
final class DefaultIndexableDataProvider implements IndexableDataProviderInterface | ||
{ | ||
use ORMTrait; | ||
|
||
public function __construct( | ||
ManagerRegistry $managerRegistry, | ||
private readonly EventDispatcherInterface $eventDispatcher, | ||
) { | ||
$this->managerRegistry = $managerRegistry; | ||
} | ||
|
||
public function getIds(string $entity, Index $index): \Generator | ||
{ | ||
$qb = $this | ||
->getManager($entity) | ||
->createQueryBuilder() | ||
->select('o.id') | ||
->from($entity, 'o') | ||
; | ||
|
||
$this->eventDispatcher->dispatch(new QueryBuilderForDataProvisionCreated($entity, $index, $qb)); | ||
|
||
/** @var SelectBatchIteratorAggregate<array-key, string|int> $batch */ | ||
$batch = SelectBatchIteratorAggregate::fromQuery($qb->getQuery(), 100); | ||
|
||
yield from $batch; | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMeilisearchPlugin\DataProvider; | ||
|
||
use Setono\SyliusMeilisearchPlugin\Config\Index; | ||
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface; | ||
|
||
interface IndexableDataProviderInterface | ||
{ | ||
/** | ||
* Returns ids of objects of the given entity that should be indexed | ||
* | ||
* @param class-string<IndexableInterface> $entity | ||
* | ||
* @return iterable<array-key, string|int> | ||
*/ | ||
public function getIds(string $entity, Index $index): iterable; | ||
} |
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
18 changes: 0 additions & 18 deletions
18
src/Event/EntityBasedQueryBuilderForIndexingCreatedEvent.php
This file was deleted.
Oops, something went wrong.
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMeilisearchPlugin\Event; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use Setono\SyliusMeilisearchPlugin\Config\Index; | ||
use Setono\SyliusMeilisearchPlugin\Model\IndexableInterface; | ||
|
||
final class QueryBuilderForDataProvisionCreated | ||
{ | ||
public function __construct( | ||
/** @var class-string<IndexableInterface> $entity */ | ||
public readonly string $entity, | ||
public readonly Index $index, | ||
public readonly QueryBuilder $qb, | ||
) { | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Setono\SyliusMeilisearchPlugin\Indexer; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @template T | ||
*/ | ||
final class IndexBuffer | ||
{ | ||
private int $count = 0; | ||
|
||
/** @var list<T> */ | ||
private array $buffer = []; | ||
|
||
/** | ||
* @param \Closure(list<T>):void $callback | ||
*/ | ||
public function __construct(private readonly int $bufferSize, private readonly \Closure $callback) | ||
{ | ||
} | ||
|
||
/** | ||
* @param T $item | ||
*/ | ||
public function push(mixed $item): void | ||
{ | ||
$this->buffer[] = $item; | ||
++$this->count; | ||
|
||
if ($this->count >= $this->bufferSize) { | ||
$this->flush(); | ||
} | ||
} | ||
|
||
public function flush(): void | ||
{ | ||
if ($this->count > 0) { | ||
($this->callback)($this->buffer); | ||
$this->buffer = []; | ||
$this->count = 0; | ||
} | ||
} | ||
} |
Oops, something went wrong.