Switch to explicitly-added callbacks. #1175
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Given this code will almost always be invoked from within an ActiveRecord model, the
model
argument will beself
.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
andpath
. Behaviour is an array of symbols, which include the following::sql
for SQL-backed indices.:real_time
for real-time indices.:deltas
if the SQL-backed indices have deltas enabled.:updates
ifattribute_updates
is configured to true (which is probably not the case for many people). This is only for SQL-backed indices.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 forThinkingSphinx::RealTime.callback_for
(but it continues to work for now).