Closed krauselukas closed 3 years ago
Thanks for raising this :)
One thing to note is that after_save
is invoked for both creates and updates (so, the callback should have still been firing, but perhaps with incomplete data changes). I think you're right in waiting for the transaction to be committed before updating Sphinx, so I've switched over to after_commit
instead - albeit with different approaches for destroys vs creates/updates, as it's invoked in all cases.
It all seemed fine on my machine, and hopefully CI agrees - I'll try to get a new release out today.
Just pushed 5.3.0 with this fix :)
@pat thanks for the quick response and release!
Recently I realized that the attribute fields of an associated model were not updated after the associated model got deleted. Since the way we use TS differs a bit from the documentation, I started to adjust the code to use TS how its documented, but I ended up having the same issue. After looking a bit through the TS codebase I started wondering where the
after_update
callbacks are taken into account for the real time indexes.To me it looks like the the appender class only adds the
after_save
andafter_destroy
callbacks for real_time.https://github.com/pat/thinking-sphinx/blob/2c8d3e7a9509407148786f2f7697580b8e19f21f/lib/thinking_sphinx/callbacks/appender.rb#L42 https://github.com/pat/thinking-sphinx/blob/2c8d3e7a9509407148786f2f7697580b8e19f21f/lib/thinking_sphinx/callbacks/appender.rb#L26
To give a little more detail, here a little snippet of the code I used: https://gist.github.com/krauselukas/1aabfb4ecd3d61b6486916237eabdcfb
The problem I faced here is that after I deleted an
Attrib
associated to aPackage
, theattrib_type_ids
in thepackage_index
still contained the id of the deletedAttrib
.So
Package.search("foo", :with => { :attrib_type_ids => 1 } )
still returned thePackage
even the associatedAttrib
was already deleted.