-
Notifications
You must be signed in to change notification settings - Fork 45
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
gatsby-plugin-algolia is deleting my entire index before writing to it #93
Comments
Hi @miketheo423, I've published 0.12.0 which solves this use case. However it requires you do the following:
|
Hey @Haroenv , I am using the enablePartialUpdates flag and and passing in a field that I know the other objects definitely do not have but it still seems to blow everything out |
Reopening to investigate |
Here's an example of what i'm attempting to pass in now. algolia-queries.js
gatsby-config.js
This is what happened when I ran my build:
|
@Haroenv Does that need to be UPDATE: |
ah, I think that the plugin isn't yet written to allow dots in |
@Haroenv Yeah it looks like the top-level attribute is yielding the same result unfortunately. |
Do you have a reproduction? With a top-level attribute that only exists in the Gatsby index I don't see an issue |
Hi @Haroenv, |
I'm not sure what you mean. Could you make a reproduction or a script that makes this index + Gatsby configuration which removes the index? I've tried this multiple times, and as long as the Gatsby index has an attribute on top-level which is used for |
After getting this issue myself I think I have an idea why this is happening, which I think is just a misunderstanding of how In the source, you check if any of the Object.keys(algoliaObjects).forEach(objectID => {
// if the object has one of the matchFields, it should be removed,
// but objects without matchFields are considered "not controlled"
// and stay in the index
if (matchFields.some(field => algoliaObjects[objectID][field])) {
currentIndexState.toRemove[objectID] = true;
}
});
} While this may work for the boolean flag on a Before digging into the source, I made the same assumption about how the plugin works. (I actually also made the same assumption about the @Haroenv what would you think about adding a predicate function to the plugin config (and maybe even per query?) which takes an object representing the previous value and returns true / false based on whether or not the object should be updated in the index? Passing a function rather than an array of strings would allow both for the |
I think that makes sense @prichey. If it makes more sense, since this plugin is still in 0.x, if you find a more clean way to express the API, don't hesitate to make breaking changes. Thanks! |
Sounds good, I'll work on some changes then PR. I'm actually also interested in making some changes to add a That being the case, @Haroenv would you prefer I make 2 separate PR's or are you fine with accepting one that addresses both issues? |
separate PRs will be easier to review, thanks @prichey ! |
@miketheo423 Have you tried updating to the most recent version? This should be fixed now |
Let's assume it's fixed :) If not, please open a new issue with reproduction |
I am writing to the same index from two different sources. One of which is using the 'algoliasearch' package in a node backend, and the other, using the gatsby-plugin-algolia to read and write from strapi. The objects on the backend are being added first, then after the gatsby build is complete, the plugin runs and deletes everything. I'm wondering if there is a way to use both of these methods to write to the same index without them colliding.
The text was updated successfully, but these errors were encountered: