-
Notifications
You must be signed in to change notification settings - Fork 470
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
Update index after soft delete #1057
Comments
Hi Chris Thinking Sphinx won't automatically ignore soft-deleted records when indexing - you'll want to have a WHERE clause in your index definition to ensure that. As for the callbacks - Thinking Sphinx will mark a record as 'deleted' when |
Hi Pat, The callback you noted is what I was looking for and it fixed my issue. It appears as long as the record is marked as deleted in Sphinx no additional query options are needed to filter out "deleted" records. Thanks for your help. |
Unfortunately there seems to be no clean way to delete instance in case callbacks are disabled. For example disable all callbacks and insert own callbacks. |
Hi @akostadinov - can you provide an example of the callbacks you're using instead? Also, may be worth continuing this discussion as a new issue (and if you can, do let me know what versions of Thinking Sphinx and Rails you're using - callbacks in TS have evolved in the last few years). |
This is current background worker that we use: class SphinxAccountIndexationWorker < SphinxIndexationWorker
def perform(account)
if account.will_be_deleted?
to_delete = account.buyers.pluck(:id) << account.id
# This is how deletion is performed by ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks#delete_from_sphinx
# Alternatively, we could delete individual records one by one with:
# ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks.after_destroy(instance)
indices(account).each do |index|
ThinkingSphinx::Deletion.perform index, to_delete
end
else
super
end
end
end This is thinking-sphinx 3.4, upgrading to 5.4 right now, seems to work the same as far as I can tell. I opened a related issue #1215, #1216 One option would be to check whether model instance can be found in the index scope or not. When it can no longer be found in scope, then delete it. In this way |
Pat,
I introduced soft delete to a couple models using ActsAsParanoid.
Strangely, I have one record that has been destroyed (has a "deleted_at" value) but it still shows up in the TS query. I read on another thread that TS has its own post destroy hook to update the indexed record. I'm guessing that hook was not called for this particular record. I've tried
ts:rebuild
andts:reindex
but I can't get that record to stop showing up. Any ideas?The text was updated successfully, but these errors were encountered: