-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Running WP_CLI command wp algolia reindex --all
would clear index even if --clear flag is not specified
#442
Comments
Hi @menno-ll Looking things over, and here's some notes that I have about this topic as a whole. I'm pretty sure our That method is being defined at https://github.com/algolia/algoliasearch-client-php/blob/3.3.2/src/SearchIndex.php#L277-L287 which is known to be in an older version of their PHP library, but this would essentially be the version we presently ship with the plugin. Here's where the filter you're using in the associated pull request is being used at: https://github.com/WebDevStudios/wp-search-with-algolia/blob/main/includes/indices/class-algolia-index.php#L539-L555. My biggest question is how often is this filter getting reached? From what I can see, if someone isn't calling I don't think it'd be super detrimental to performance and whatnot, but I also won't claim it's necessarily "ideal" either. More a case of "being extra sure". I also know that the way Algolia themselves originally designed the plugin, and a detail we haven't really attempted to re-evaluate and redesign, is when doing bulk re-indexing like this, to just "wipe out" the original index and push up everything as if it was new. This is being done instead of trying to do a bunch of patch/update pushes for each piece of content. I'd need to inquire to Algolia devs to see if creating an outright new object is more efficient and performant than trying to compare/update existing items. Not going to close this issue outright, as I think it could use some pondering and considerations and discussion, but I did want to at least attempt to provide as much context as I could. |
Hi @tw2113 The code path that now triggers the clearing of the index, while
So this will cause to actually clear everything from the index when using the CLI command, ignoring the This behavior can be modified by using the Then regarding your question about how many times the filter will run.
Regarding performance, I don't know the impact yet, as we ourselves have only used Algolia for a short time now, and just stumbled on this issue, which seemed quite easy to fix. If I have to speculate, I would think that clearing the index thats already empty isn't that hard of a task, and as it's only a CLI command wont have a large impact on performance. |
I almost had a big reply typed up for you, but as I continued to think about things, I put a pause on myself as I wanted to circle back to when I had some more time to really ponder and think things through some more. Looking through the git history for our repo, and it's important to note that we are a fork of a WordPress plugin that Algolia originally created and then archived, but this double clearing has been there from the start of our plugin. That means that it was also doubled up in Algolia's original. While I generally believe and hold to the idea that they knew what they were doing and were intentional with it, no one is perfect either, and I think this is one of those spots. All that to say that I think we can get this corrected, and in a way that I believe would not risk any backwards compatibility issues, especially since this would largely be stemming from just the WP-CLI component. The I'm thinking that we need to set, say
This, would necessitate adding a 3rd parameter to the
Finally, changing While yes the filter is available and in place, I feel like this is going to be the more advantageous route to go while also managing to preserve backwards compatibility. The WP-CLI That said, if things make sense for above, and you're willing to try them out for your own usecases, but also issue the PR for the changes, we'd love the contributions and we'd definitely give credit in the changelog for it as well. |
Hi @tw2113 I read your comment and I have to say I've walked the exact same path in my head. However I looked at the other code in the project, and had seen that instead of their accepted I did however not know it was a plugin originally created by Algolia and then abandoned by them. And that all the code in there is "their legacy". I'm also happy to implement the changes you suggest and will update the PR for you. |
Hi @tw2113 I've modified my PR, using the changes you have suggested. As an extra, I found that the filter was used also in some WP All Import (also known as pmxi?) sync functionality. |
Had exactly the same issue just now with I feel like I've hit the jackpot with this thread! Recent, detailed, PR submitted. Much appreciated! |
due to the holidays at least here in the US, we're probably not doing any sort of release until 2025, but we'll definitely keep this around and ready. I'd also like to do at least some testing to make sure we're not seeing potential issues. |
Good to know @tw2113, thanks! Happy holidays! Hi @graham73may!
After release of the change and then updating the plugin update in your site, you should be able to delete this filter again. |
Describe the bug
When you run the wp-cli command
wp algolia reindex --all
the index would still be cleared.This happens because when it re-indexes the first batch, it checks if the index exists.
And inside that functionality, it also empties the index if the index already existed.
To Reproduce
Steps to reproduce the behavior:
wp algolia reindex --all
wp algolia reindex --all
Expected behavior
Index should not be cleared when the
--clear
flag has not been specified.Screenshots
If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
Smartphone (please complete the following information):
Cannot run wp-cli on smartphone
Additional context
Add any other context about the problem here.
Fix would be to add
add_filter( 'algolia_clear_index_if_existing', '__return_false' );
toclass-algolia-cli.php
in an else statement, somewhere around line126
.The text was updated successfully, but these errors were encountered: