pimcore / generic-data-index-bundle

Other
3 stars 1 forks source link

Do not delete and recreate index on class definitions save #127

Closed markus-moser closed 2 months ago

markus-moser commented 3 months ago

In the portal engine v3.0 it worked the same way like now. Each class definition save will trigger a recreation of the related search index. Therefore the index is empty until the queue is finished.

We should fine a different approach for this. The index mapping update already works in a way that the native reinding will be used to create the new index when the mapping cannot be updated directly. This approach would be fine, the only potential problem is that this reindex mechanism could take a minute for very large amounts of data objects. Therefore the current approach of doing this synchronously is not practicable. We could change it to a message worker but the problem is that the running workers will not get the updated class definition. Therefore we need to restart the message workers (see https://github.com/pimcore/pimcore/blob/11.x/lib/Helper/StopMessengerWorkersTrait.php).

One problem is also that all OpenSearch document updates are somehow patch updates instead of full updates. So when fields get deleted currently the documents will still contain the data after the update. We had this problem also in the message handler created here: https://github.com/pimcore/generic-data-index-bundle/pull/128. There we recreated all indices when the language changed to solve this problem. But on a live system we should really try to avoid this. Possible solutions are:

  1. Find a way to do a full update of a document instead of the current patch update approach

  2. Add a separte operation type to the index update queue table in addition to "update". Maybe something like "replace". When "replace" is set the index could then delete the document directly before the update and afterwards re-add it. Our index update methods (updateAll(),...) would then need a option to define this operation type when enqueueing all relevant items.

markus-moser commented 3 months ago

@fashxp Do you have a good idea how to solve this? Maybe we can do a short discussion on this?

fashxp commented 3 months ago

sure. we could trigger a worker restart on class definition save? we do that already on several places when configs are saved.

markus-moser commented 3 months ago

Do you have a example where we do this?

markus-moser commented 3 months ago

Ahh I see, we do it here:

https://github.com/pimcore/pimcore/blob/11.x/lib/Helper/StopMessengerWorkersTrait.php

Yes, let's solve it like this!