algolia / gatsby-plugin-algolia

A plugin to push to Algolia based on graphQl queries
https://yarn.pm/gatsby-plugin-algolia
Apache License 2.0
178 stars 45 forks source link

Plugin is deleting Sanity document from index if edited. #180

Closed alexander-digett closed 1 year ago

alexander-digett commented 1 year ago

We have 81 documents from Sanity that get indexed via this plugin. If a Sanity CMS editor edits a document and leaves it edited and not published(After the document has already been published and indexed previously.), the document will get deleted from the index(although I can't replicate on demand.. it happens every once in a while).

I see the deleteObject code in this plugin which checks to see if the objectID is not in the new array... but from what I can tell that ID should still be there as the document is still available via the frontend, and I'm console logging the objectID(Sanity ID). I also see in the API monitoring of algolia the objectID's getting deleted.

gatsby-plugin-algolia version: 0.26.0 gatsby version: 4.12.1

Thanks to anyone that can shed some light on this issue!

Haroenv commented 1 year ago

Do you think it's possible that the GraphQL query excludes the edited, non-saved items? is there a reproduction of items that don't show up?

alexander-digett commented 1 year ago

I don't think so. I'm filtering out via regex sanity draft documents in our algolia query. If I build the site again without touching anything the items get indexed again correctly, but a few days later if they are still being edited and not yet published they will get removed from index again. It's a real pain to debug as it happens just once every few days. I have been leaving documents edited on purpose to try to replicate the issue every few days.

Haroenv commented 1 year ago

If the only data source is Sanity, I'd also look at https://www.sanity.io/plugins/sanity-algolia to avoid a lack of synchronisation.

I don't know what the source of this could be, this plugin only deletes items that are not in the query

Are the objectIDs stable?