monsieurbiz / SyliusSearchPlugin

A search plugin using Elasticsearch for Sylius
MIT License
45 stars 38 forks source link

Reindex event is not triggered when having multiple flush() #141

Closed tmarly closed 2 years ago

tmarly commented 2 years ago

Hi,

I do not understand the reason of this line:

class ReindexProductEventSubscriber implements EventSubscriberInterface, LoggerAwareInterface
{
    // (...) 
    public function onFlush(OnFlushEventArgs $eventArgs): void
    {
        // (...)
        $eventArgs->getEntityManager()->getEventManager()->removeEventListener(Events::onFlush, $this);
        // (...)
    }
 }

Why removing the event listener on the onFlush event ? If I'm calling $em->flush() a second time, products won't trigger the event, so they won't be reindexed ...

delyriand commented 2 years ago

Hello @tmarly,

Thanks for your issue.

We need to review the management of events... The removeEventListener prevent an infinite loop when we dispatch the reindex message (with doctrine transport).

For the moment, I have added a workaround to dispatch manually message (in my example for product import) in PR #138. This should help you manage your case.

tmarly commented 2 years ago

Indeed my need is to import many products, so your PR is perfect, thanks 👍