Soft deleting users, default scopes

4 views
Skip to first unread message

Simone Miller

unread,
Feb 6, 2019, 4:34:22 AM2/6/19
to thinkin...@googlegroups.com
Hi Pat

May I check in with you about an issue we're having with soft deleted users being filtered out of searches? 

We're runnning thinking sphinx 4.0.0 with real time indices, soft deleting users (without active record destroy callbacks) and have a default scope on users { where(:deleted_at => nil) }
We run 'flying-sphinx regenerate' each night - after which deleted users no longer show up in searches. Are we right in thinking that having the default scope means deleted users won't be added to the index?

We are going to remove the default scope! In the meantime, is there a way to prevent thinking-sphinx from filtering out deleted users / unscoping our default scope when the index is being generated? We're trying to avoid batch updating deleted users to manually trigger real time callbacks.

We also noticed in development that running rake ts:index doesn't filter out deleted users, but running rake ts:rebuild does. Could you explain why this is?

Thank you
Simone

Pat Allan

unread,
Feb 15, 2019, 9:28:00 PM2/15/19
to thinkin...@googlegroups.com
Hi Simone,

Sorry for the delay in responding to this.

The default scope only has an impact when inserting/updating all records into Sphinx (via ts:index/ts:rebuild). If changes are made to a soft-deleted instance which fires the callback there, then the real-time processing will do its thing on just that record, and it’ll find itself back in Sphinx.

Also, as you’ve noted, ts:index does not delete existing records - it just updates existing ones and inserts new ones. A rebuild, on the other hand, clears out existing index data first.

If you’re not using a default scope, then you can set your real-time index’s scope to load only what you want:

And to avoid callback behaviour in these soft-deleted instances, instead of using the default TS approach, you’ll want to have your own callback instead:

Hope all this helps! Do let me know if there are further questions.

Cheers,

— 
Pat

--
You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to thinking-sphi...@googlegroups.com.
To post to this group, send email to thinkin...@googlegroups.com.
Visit this group at https://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.

Simone Miller

unread,
Feb 25, 2019, 6:22:59 AM2/25/19
to thinkin...@googlegroups.com
Hi Pat

Thanks very much for getting back - that fixed things for us.
Hope all went well with the Ruby Conference, 

Best for now and many thanks
Simone
Reply all
Reply to author
Forward
0 new messages