From ea35340e3cd0a6cbbc4acb86a366cf1ee83ac961 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 8 Aug 2021 12:11:12 +1000 Subject: [PATCH 1/2] fix: load ActiveRecord component after Rails init This isn't quite as neat as ea8bc34ef71615523ae4159e851fa514338c14a8 (as I like the idea of waiting until ActiveRecord is loaded by Rails itself), but it seems Rake tasks don't always load ActiveRecord, and so we end up in a situation where indices are being loaded without TS's ActiveRecord components being available (see https://github.com/pat/thinking-sphinx/issues/1199). But: the main issue was that prior to @jdelStrother's good work, AR configuration in initialisers was being ignored. This new approach waits until after initialisers have been run, so it should be fine. --- lib/thinking_sphinx/railtie.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/thinking_sphinx/railtie.rb b/lib/thinking_sphinx/railtie.rb index 668a0e89..fe90d795 100644 --- a/lib/thinking_sphinx/railtie.rb +++ b/lib/thinking_sphinx/railtie.rb @@ -5,12 +5,12 @@ class ThinkingSphinx::Railtie < Rails::Railtie ThinkingSphinx::Configuration.reset end - initializer 'thinking_sphinx.initialisation' do - ActiveSupport.on_load(:active_record) do - require 'thinking_sphinx/active_record' - ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base - end + 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( From 3796166607907cc6ca7fe8e31f60d17e99500b6b Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Mon, 9 Aug 2021 11:27:05 +1000 Subject: [PATCH 2/2] 5.2.1 --- CHANGELOG.markdown | 8 ++++++++ README.textile | 2 +- thinking-sphinx.gemspec | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 9f85326b..43494b8b 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -2,6 +2,14 @@ All notable changes to this project (at least, from v3.0.0 onwards) are documented in this file. +## 5.2.1 - 2021-08-09 + +[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.2.1) + +### Fixed + +* Ensure ActiveRecord components are loaded for rake tasks, but only after the Rails application has initialised. More details in [#1199](https://github.com/pat/thinking-sphinx/issues/1199). + ## 5.2.0 - 2021-06-12 [Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.2.0) diff --git a/README.textile b/README.textile index f5c1ca0a..3a855888 100644 --- a/README.textile +++ b/README.textile @@ -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.0. +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. h2. Upgrading diff --git a/thinking-sphinx.gemspec b/thinking-sphinx.gemspec index f08fefb1..5a10d80d 100644 --- a/thinking-sphinx.gemspec +++ b/thinking-sphinx.gemspec @@ -5,7 +5,7 @@ $:.push File.expand_path('../lib', __FILE__) Gem::Specification.new do |s| s.name = 'thinking-sphinx' - s.version = '5.2.0' + s.version = '5.2.1' s.platform = Gem::Platform::RUBY s.authors = ["Pat Allan"] s.email = ["pat@freelancing-gods.com"]