pat / thinking-sphinx

Sphinx/Manticore plugin for ActiveRecord/Rails
http://freelancing-gods.com/thinking-sphinx
MIT License
1.63k stars 470 forks source link

Switch to explicitly-added callbacks. #1175

Closed pat closed 4 years ago

pat commented 4 years ago

As discussed in #1173 and initially prompted by discussions in #1158, this commit removes the automatic insertion of callbacks into every single ActiveRecord model, and instead expects them to be explicitly added to the models that are indexed. The syntax is as follows:

ThinkingSphinx::Callbacks.append(model, reference, options, &block)

Given this code will almost always be invoked from within an ActiveRecord model, the model argument will be self.

The reference is optional, but should match the first argument of the index in question. e.g. it’ll likely be the model name, lowercase and underscored, as a symbol. If the model is namespaced, though, this should be a string, with slashes to indicate the namespacing (like how a namespaced index is defined).

The options are behaviour and path. Behaviour is an array of symbols, which include the following:

Both the path option and the block argument are the same as what would have been passed into ThinkingSphinx::RealTime.callback_for, and have no impact for SQL-backed callbacks. This new approach replaces the need for ThinkingSphinx::RealTime.callback_for (but it continues to work for now).