Skip to content

Commit

Permalink
Merge branch 'release/v5.3.0' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Aug 19, 2021
2 parents 9f4a881 + cbc2fb0 commit b8560be
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 26 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@

All notable changes to this project (at least, from v3.0.0 onwards) are documented in this file.

## 5.3.0 - 2021-08-19

[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.3.0)

### Changed

* StaleIdsExceptions now include a URL in their error message with recommendations on how to resolve the problem.
* Fire real-time callbacks on `after_commit` (including deletions) to ensure data is fully persisted to the database before updating Sphinx. More details in [#1204](https://github.com/pat/thinking-sphinx/pull/1204).

### Fixed

* Ensure Thinking Sphinx's ActiveRecord components are loaded by either Rails' after_initialise hook or ActiveSupport's on_load notification, because the order of these two events are not consistent.
* Remove `app/indices` from eager_load_paths in Rails 4.2 and 5, to match the behaviour in 6.

## 5.2.1 - 2021-08-09

[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.2.1)
Expand Down
4 changes: 2 additions & 2 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
h1. Thinking Sphinx

Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v5.2.1.
Thinking Sphinx is a library for connecting ActiveRecord to the Sphinx full-text search tool, and integrates closely with Rails (but also works with other Ruby web frameworks). The current release is v5.3.0.

h2. Upgrading

Expand All @@ -14,7 +14,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp

<pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
gem 'thinking-sphinx', '~> 5.2'</code></pre>
gem 'thinking-sphinx', '~> 5.3'</code></pre>

The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.

Expand Down
6 changes: 1 addition & 5 deletions lib/thinking_sphinx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,6 @@ module Subscribers; end
require 'thinking_sphinx/logger'
require 'thinking_sphinx/real_time'

if defined?(Rails::Railtie)
require 'thinking_sphinx/railtie'
else
require 'thinking_sphinx/active_record'
end
require 'thinking_sphinx/railtie' if defined?(Rails::Railtie)

ThinkingSphinx.before_index_hooks << ThinkingSphinx::Hooks::GuardPresence
2 changes: 2 additions & 0 deletions lib/thinking_sphinx/active_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,5 @@ module Depolymorph; end
require 'thinking_sphinx/active_record/depolymorph/overridden_reflection'
require 'thinking_sphinx/active_record/depolymorph/scoped_reflection'
require 'thinking_sphinx/active_record/filter_reflection'

ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
class ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks <
ThinkingSphinx::Callbacks

callbacks :after_destroy, :after_rollback
callbacks :after_commit, :after_destroy, :after_rollback

def after_commit
delete_from_sphinx
end

def after_destroy
delete_from_sphinx
Expand Down
10 changes: 7 additions & 3 deletions lib/thinking_sphinx/callbacks/appender.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ def call
attr_reader :model, :reference, :options, :block

def add_core_callbacks
model.after_destroy ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks
model.after_commit(
ThinkingSphinx::ActiveRecord::Callbacks::DeleteCallbacks,
on: :destroy
)
end

def add_delta_callbacks
Expand All @@ -40,8 +43,9 @@ def add_delta_callbacks
end

def add_real_time_callbacks
model.after_save ThinkingSphinx::RealTime.callback_for(
reference, path, &block
model.after_commit(
ThinkingSphinx::RealTime.callback_for(reference, path, &block),
on: [:create, :update]
)
end

Expand Down
22 changes: 12 additions & 10 deletions lib/thinking_sphinx/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ class ThinkingSphinx::Railtie < Rails::Railtie

config.after_initialize do
require 'thinking_sphinx/active_record'
ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base
end

initializer 'thinking_sphinx.initialisation' do
if ActiveSupport::VERSION::MAJOR > 5
if Rails.application.config.autoloader == :zeitwerk
ActiveSupport::Dependencies.autoload_paths.delete(
Rails.root.join("app", "indices").to_s
)
end
ActiveSupport.on_load(:active_record) do
require 'thinking_sphinx/active_record'
end

Rails.application.config.eager_load_paths -=
ThinkingSphinx::Configuration.instance.index_paths
Rails.application.config.eager_load_paths.freeze
if ActiveSupport::VERSION::MAJOR > 5 &&
Rails.application.config.autoloader == :zeitwerk
ActiveSupport::Dependencies.autoload_paths.delete(
Rails.root.join("app", "indices").to_s
)
end

Rails.application.config.eager_load_paths -=
ThinkingSphinx::Configuration.instance.index_paths
Rails.application.config.eager_load_paths.freeze
end

rake_tasks do
Expand Down
3 changes: 2 additions & 1 deletion lib/thinking_sphinx/search/stale_ids_exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ def initialize(ids, context)
end

def message
"Record IDs found by Sphinx but not by ActiveRecord : #{ids.join(', ')}"
"Record IDs found by Sphinx but not by ActiveRecord : #{ids.join(', ')}\n" \
"https://freelancing-gods.com/thinking-sphinx/v5/common_issues.html#record-ids"
end
end
2 changes: 1 addition & 1 deletion lib/thinking_sphinx/sinatra.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
require 'thinking_sphinx'

ActiveSupport.on_load :active_record do
include ThinkingSphinx::ActiveRecord::Base
require 'thinking_sphinx/active_record'
end
2 changes: 1 addition & 1 deletion spec/acceptance/sql_deltas_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
)
sleep 0.25

expect(Book.search('Terry Pratchett').to_a).to eq([guards, men])
expect(Book.search('Terry Pratchett').to_a).to match_array([guards, men])
end

it "automatically indexes updated records" do
Expand Down
4 changes: 3 additions & 1 deletion spec/thinking_sphinx/active_record/index_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
describe ThinkingSphinx::ActiveRecord::Index do
let(:index) { ThinkingSphinx::ActiveRecord::Index.new :user }
let(:config) { double('config', :settings => {},
:indices_location => 'location', :next_offset => 8) }
:indices_location => 'location', :next_offset => 8,
:index_set_class => index_set_class) }
let(:index_set_class) { double :reference_name => :user }

before :each do
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
Expand Down
2 changes: 1 addition & 1 deletion thinking-sphinx.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $:.push File.expand_path('../lib', __FILE__)

Gem::Specification.new do |s|
s.name = 'thinking-sphinx'
s.version = '5.2.1'
s.version = '5.3.0'
s.platform = Gem::Platform::RUBY
s.authors = ["Pat Allan"]
s.email = ["[email protected]"]
Expand Down

0 comments on commit b8560be

Please sign in to comment.