Describe the bug
With protected content enabled interactions in the admin can result in inconsistent information.
Steps to Reproduce
On a small site with minimal plugins
Create a post and save it
In the post listing, click on trash to put the item in the trash
Note that when the page refreshes the item is still shown in the listing
Refresh the listing, note that the item has now no longer in the list
Expected behavior
Clicking trash would result in the post no longer being listed
Environment information
Plugins and version: I tested using 2.8 through 3.1
Theme and version: default WP theme on 5.2.2
Other installed plugin(s) and version(s): no other plugins
Cause and potential solution
This issue occurs because the request to update the post in Elasticsearch doesn't wait for Elasticsearch to commit the change, that is Elasticsearch returns immediately. The change isn't reflected in search results until the next refresh interval has fired which defaults to 1 second. When the WordPress admin loads again it does a search against an old copy of the index and gets outdated results back.
The potential solution is to add ?refresh=wait_for to the index request for the affected document(s). For performance I wouldn't recommend issuing a refresh command manually after indexing the document, only when making the index request. Manually issuing a refresh will just result in a doubled up refresh (because ES is already doing scheduled refreshes anyway) potentially causing more delay than necessary.
I also wouldn't use wait_for unless the command came from the admin page while users are making changes they would expect to be fresh on the next page load.
It maybe useful to allow for disable waiting in the event ES is configured with a longer than usual refresh interval.
Just tested this and $path = apply_filters( 'ep_bulk_index_request_path', $index . '/_bulk?refresh=wait_for', $body, $type ); really fixes the problem.
Describe the bug With protected content enabled interactions in the admin can result in inconsistent information.
Steps to Reproduce
Expected behavior Clicking trash would result in the post no longer being listed
Environment information
Cause and potential solution This issue occurs because the request to update the post in Elasticsearch doesn't wait for Elasticsearch to commit the change, that is Elasticsearch returns immediately. The change isn't reflected in search results until the next refresh interval has fired which defaults to 1 second. When the WordPress admin loads again it does a search against an old copy of the index and gets outdated results back.
The potential solution is to add
?refresh=wait_for
to the index request for the affected document(s). For performance I wouldn't recommend issuing a refresh command manually after indexing the document, only when making the index request. Manually issuing a refresh will just result in a doubled up refresh (because ES is already doing scheduled refreshes anyway) potentially causing more delay than necessary.I also wouldn't use
wait_for
unless the command came from the admin page while users are making changes they would expect to be fresh on the next page load.It maybe useful to allow for disable waiting in the event ES is configured with a longer than usual refresh interval.