Skip to content
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

Switch to explicitly-added callbacks. #1175

Merged
merged 1 commit into from
Jul 20, 2020
Merged

Switch to explicitly-added callbacks. #1175

merged 1 commit into from
Jul 20, 2020

Conversation

pat
Copy link
Owner

@pat pat commented Jul 19, 2020

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:

  • :sql for SQL-backed indices.
  • :real_time for real-time indices.
  • :deltas if the SQL-backed indices have deltas enabled.
  • :updates if attribute_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 for ThinkingSphinx::RealTime.callback_for (but it continues to work for now).

As discussed in #1173, 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:
* :sql for SQL-backed indices.
* :real_time for real-time indices.
* :deltas if the SQL-backed indices have deltas enabled.
* :updates if `attribute_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 for `ThinkingSphinx::RealTime.callback_for` (but it continues to work for now).
@pat pat merged commit df2746b into develop Jul 20, 2020
krauselukas added a commit to openSUSE/open-build-service that referenced this pull request Jul 22, 2020
Thinking Sphinx v5.0 introduces explicit callbacks. Since we
are using the real time indices, we already have explicit
callbacks set. But at the same time, a new syntax for the
callback got introduced with:
-> pat/thinking-sphinx#1175
The old way is still supported, but in the changelogs it
is recommended to adapt the new style right away.
krauselukas added a commit to openSUSE/open-build-service that referenced this pull request Jul 22, 2020
Thinking Sphinx v5.0 introduces explicit callbacks. Since we
are using the real time indices, we already have explicit
callbacks set. But at the same time, a new syntax for the
callback got introduced with:
-> pat/thinking-sphinx#1175
The old way is still supported, but in the changelogs it
is recommended to adapt the new style right away.
krauselukas added a commit to openSUSE/open-build-service that referenced this pull request Jul 22, 2020
Thinking Sphinx v5.0 introduces explicit callbacks. Since we
are using the real time indices, we already have explicit
callbacks set. But at the same time, a new syntax for the
callback got introduced with:
-> pat/thinking-sphinx#1175
The old way is still supported, but in the changelogs it
is recommended to adapt the new style right away.
krauselukas added a commit to openSUSE/open-build-service that referenced this pull request Jul 23, 2020
Thinking Sphinx v5.0 introduces explicit callbacks. Since we
are using the real time indices, we already have explicit
callbacks set. But at the same time, a new syntax for the
callback got introduced with:
-> pat/thinking-sphinx#1175
The old way is still supported, but in the changelogs it
is recommended to adapt the new style right away.
krauselukas added a commit to openSUSE/open-build-service that referenced this pull request Jul 23, 2020
Thinking Sphinx v5.0 introduces explicit callbacks. Since we
are using the real time indices, we already have explicit
callbacks set. But at the same time, a new syntax for the
callback got introduced with:
-> pat/thinking-sphinx#1175
The old way is still supported, but in the changelogs it
is recommended to adapt the new style right away.
@pat pat deleted the rework-callbacks branch December 21, 2021 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant