MattieBelt / mattie-strapi-bundle

Mattie plugin bundle for Strapi
https://mattie-bundle.mattiebelt.com
MIT License
40 stars 19 forks source link

When unpublish an item, it should be deleted from algolia #117

Closed sauldeleon closed 2 years ago

sauldeleon commented 2 years ago

Hi! thanks a lot for this plugin!

I have an use case and would like to know your opinion!

When we publish a new item, the plugin triggers and sets the item in algolia, which is fine.

But when the opposite happens? what if I unpublish an item? should it be removed from algolia?

I think it should but currently it is not happening. Right? How can we achieve this?

thanks in advance!

sauldeleon commented 2 years ago

Hello, I have seen that you just set the publishedAt field to null. If this the expected behaviour, then you can close this task!

Thanks again for you work on this!

P.S I think rather than setting the value to NULL, it would be better to set a date like 1 Jan 1970 or a boolean value to false, as we cannot filter in algolia by null, on the other hand we can filter unpublished post adding a facet or something.

What do you think?

sauldeleon commented 2 years ago

I think honestly you can close this issue. I guess is strapi who is setting publishedAt to null. So nothing can be done from this plugin.

Thanks again!

sauldeleon commented 2 years ago

Related: https://github.com/MattieBelt/mattie-strapi-bundle/pull/109

@MattieBelt what do you think about this PR? can it be merged?

Jake-Nichols-Soak commented 2 years ago

Sorry to bump a closed issue but we're running into lots of issues with Algolia showing drafts/deleted content, any chance the PR mentioned above could be brought in to solve this? @MattieBelt

sauldeleon commented 2 years ago

Hello @Jake-Nichols-Soak

I dont know what is your exact issue, What I have done is not ideal, is querying by algolia and then do a quick code threatment of skipping published === null values

It is not ideal, because if you are loading paginated results and you want 10, in those 10 you could have 10 unpublished items, which implies showing 0 results despite the query went OK

On the other hand, I can possibly think on scenearios where users does not want to delete data from algolia. And according to algolia documentation there is no way of querying by someField = null. In the documentation they say that in that scenario we should set in the data someField = 'null' and query by that string...

Maybe @MattieBelt could set something like

when deleting then set value to 'I_have_been_deleted'