Page 1 of 1

JSONADM API and rebuild index

Posted: 17 Mar 2020, 16:52
by matteovg7
Hi, when a new product is associated with a category in catalog, for example, it is necessary to rebuild the index in order to view it in the frontend.
When this operation is made with JSONADM API, how is possible to rebuild the index, for example every time the new relationship is patched?
Thank you.

Re: JSONADM API and rebuild index

Posted: 18 Mar 2020, 09:53
by aimeos
There's no way to rebuild the index using the JsonAdm API because it's a potentially long running operation that takes much longer than the request is allowed to. It's also not possible to execute the cronjob from the API.

The only possibility might be to create a job in the message queue and a corresponding job controller that rebuild the index if there's a job in the queue. But there are a few things to keep an eye on: Rebuild jobs must not be executed in parallel and what if there are a lot of jobs in the queue due to several changes? Are they all executed one by one? Is only the first executed and what if another change requires to rebuild a product whose index records already has been rebuild?

Our suggestion would be to rebuild only the index entries of the product whose reference has been added, modified or deleted like it's done for the product in the JQAdm interface:
https://github.com/aimeos/ai-admin-jqad ... #L227-L228

Can you create a PR for this change?

Re: JSONADM API and rebuild index

Posted: 18 Mar 2020, 11:56
by matteovg7
https://github.com/aimeos/ai-admin-jsonadm/pull/6

I tried in my extension and this code works when adding a product in a category, so it works also when any other relationships of the product is patched.
I don't know if there are other stuff to take care (other domains that needs to rebuild the index, etc).

Re: JSONADM API and rebuild index

Posted: 18 Mar 2020, 15:47
by aimeos
Fixed a few things in your code and extended the tests:
https://github.com/aimeos/ai-admin-json ... #L438-L445

Now, PATCH and POST will update the index but still does not DELETE.

Re: JSONADM API and rebuild index

Posted: 19 Mar 2020, 08:55
by matteovg7
In the next days I will do a PR also for DELETE method.