Skip to content

Commit 0753d7e

Browse files
committed
Merge branch 'release/v5.2.0' into master
2 parents 454b026 + 1e9eb98 commit 0753d7e

13 files changed

+79
-20
lines changed

.circleci/config.yml

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ workflows:
2828
debian: buster
2929
matrix:
3030
parameters:
31-
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
31+
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2', '3.0.0' ]
3232
# - test:
3333
# database: postgresql
3434
# sphinx_version: 3.3.1
@@ -62,7 +62,7 @@ workflows:
6262
debian: buster
6363
matrix:
6464
parameters:
65-
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
65+
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2', '3.0.0' ]
6666
- test:
6767
name: "Manticore 3.5.4 with PostgreSQL"
6868
database: postgresql
@@ -71,7 +71,7 @@ workflows:
7171
debian: buster
7272
matrix:
7373
parameters:
74-
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2' ]
74+
ruby: [ '2.4.9', '2.5.8', '2.6.6', '2.7.2', '3.0.0' ]
7575

7676
jobs:
7777
test:
@@ -115,6 +115,8 @@ jobs:
115115
command: |
116116
if [ "<< parameters.ruby >>" == "2.7.2" ]; then
117117
export BUNDLER_VERSION=2.1.4
118+
elif [ "<< parameters.ruby >>" == "3.0.0" ]; then
119+
export BUNDLER_VERSION=2.1.4
118120
else
119121
export BUNDLER_VERSION=1.17.3
120122
fi

Appraisals

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@ appraise 'rails_5_0' do
1515
gem 'jdbc-mysql', '~> 5.1.36', :platform => :jruby
1616
gem 'activerecord-jdbcmysql-adapter', '~> 50.0', :platform => :jruby
1717
gem 'activerecord-jdbcpostgresql-adapter', '~> 50.0', :platform => :jruby
18-
end if RUBY_PLATFORM != "java" || ENV["SPHINX_VERSION"].to_f > 2.1
18+
end if (RUBY_PLATFORM != "java" || ENV["SPHINX_VERSION"].to_f > 2.1) && RUBY_VERSION.to_f < 3.0
1919

2020
appraise 'rails_5_1' do
2121
gem 'rails', '~> 5.1.0'
2222
gem 'mysql2', '~> 0.4.0', :platform => :ruby
23-
end if RUBY_PLATFORM != 'java'
23+
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f < 3.0
2424

2525
appraise 'rails_5_2' do
2626
gem 'rails', '~> 5.2.0'
2727
gem 'mysql2', '~> 0.5.0', :platform => :ruby
2828
gem 'pg', '~> 1.0', :platform => :ruby
29-
end if RUBY_PLATFORM != 'java'
29+
end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f < 3.0
3030

3131
appraise 'rails_6_0' do
3232
gem 'rails', '~> 6.0.0'

CHANGELOG.markdown

+14
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@
22

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

5+
## 5.2.0 - 2021-06-12
6+
7+
[Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.2.0)
8+
9+
### Added
10+
11+
* Confirmed support for Ruby 3.0.
12+
* Orphaned records in real-time indices can now be cleaned up without running `rails ts:rebuild`. Disabled by default, can be enabled by setting `real_time_tidy` to true per environment in `config/thinking_sphinx.yml` (and will need `ts:rebuild` to restructure indices upon initial deploy). More details in [#1192](https://github.com/pat/thinking-sphinx/pull/1192).
13+
14+
### Fixed
15+
16+
* Avoid loading ActiveRecord during Rails initialisation so app configuration can still have an impact ([@jdelStrother](https://github.com/jdelStrother) in [#1194](https://github.com/pat/thinking-sphinx/pull/1194)).
17+
* Remove `app/indices` (in both the Rails app and engines) from Rails' eager load paths, which was otherwise leading to indices being loaded more than once. (See [#1191](https://github.com/pat/thinking-sphinx/issues/1191) and [#1195](https://github.com/pat/thinking-sphinx/issues/1195)).
18+
519
## 5.1.0 - 2020-12-28
620

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

README.textile

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
h1. Thinking Sphinx
22

3-
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.1.0.
3+
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.
44

55
h2. Upgrading
66

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

1515
<pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
1616
gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
17-
gem 'thinking-sphinx', '~> 5.1'</code></pre>
17+
gem 'thinking-sphinx', '~> 5.2'</code></pre>
1818

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

@@ -29,18 +29,18 @@ h2. Requirements
2929
The current release of Thinking Sphinx works with the following versions of its dependencies:
3030

3131
|_. Library |_. Minimum |_. Tested Against |
32-
| Ruby | v2.4 | v2.4, v2.5, v2.6, v2.7 |
33-
| Sphinx | v2.2.11 | v2.2.11, v3.2.1 |
34-
| Manticore | v2.8 | v2.8, v3.4 |
35-
| ActiveRecord | v4.2 | v4.2..v6.0 |
32+
| Ruby | v2.4 | v2.4, v2.5, v2.6, v2.7, v3.0 |
33+
| Sphinx | v2.2.11 | v2.2.11, v3.3.1 |
34+
| Manticore | v2.8 | v2.8, v3.5 |
35+
| ActiveRecord | v4.2 | v4.2..v6.1 |
3636

3737
It _might_ work with older versions of Ruby, but it's highly recommended to update to a supported release.
3838

39-
It should also work with JRuby, but the test environment on Travis CI has been timing out, hence that's not actively tested against at the moment.
39+
It should also work with JRuby, but the test environment for that in CI has been unreliable, hence that's not actively tested against at the moment.
4040

4141
h3. Sphinx or Manticore
4242

43-
Thinking Sphinx is currently built for Sphinx 2.2.11 or newer (though it'll likely work with 2.1.x releases), or Manticore v2.8+.
43+
Thinking Sphinx is currently built for Sphinx 2.2.11 or newer, or Manticore v2.8+.
4444

4545
h3. Rails and ActiveRecord
4646

lib/thinking_sphinx.rb

+5-2
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,15 @@ module Subscribers; end
9696
require 'thinking_sphinx/utf8'
9797
require 'thinking_sphinx/wildcard'
9898
# Extended
99-
require 'thinking_sphinx/active_record'
10099
require 'thinking_sphinx/deltas'
101100
require 'thinking_sphinx/distributed'
102101
require 'thinking_sphinx/logger'
103102
require 'thinking_sphinx/real_time'
104103

105-
require 'thinking_sphinx/railtie' if defined?(Rails::Railtie)
104+
if defined?(Rails::Railtie)
105+
require 'thinking_sphinx/railtie'
106+
else
107+
require 'thinking_sphinx/active_record'
108+
end
106109

107110
ThinkingSphinx.before_index_hooks << ThinkingSphinx::Hooks::GuardPresence

lib/thinking_sphinx/railtie.rb

+5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ class ThinkingSphinx::Railtie < Rails::Railtie
77

88
initializer 'thinking_sphinx.initialisation' do
99
ActiveSupport.on_load(:active_record) do
10+
require 'thinking_sphinx/active_record'
1011
ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base
1112
end
1213

@@ -16,6 +17,10 @@ class ThinkingSphinx::Railtie < Rails::Railtie
1617
Rails.root.join("app", "indices").to_s
1718
)
1819
end
20+
21+
Rails.application.config.eager_load_paths -=
22+
ThinkingSphinx::Configuration.instance.index_paths
23+
Rails.application.config.eager_load_paths.freeze
1924
end
2025
end
2126

lib/thinking_sphinx/real_time/index/template.rb

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ def apply
1313
add_attribute primary_key, :sphinx_internal_id, :bigint
1414
add_attribute class_column, :sphinx_internal_class, :string, :facet => true
1515
add_attribute 0, :sphinx_deleted, :integer
16+
17+
if tidying?
18+
add_attribute -> (_) { Time.current.to_i }, :sphinx_updated_at, :timestamp
19+
end
1620
end
1721

1822
private
@@ -34,7 +38,15 @@ def class_column
3438
[:class, :name]
3539
end
3640

41+
def config
42+
ThinkingSphinx::Configuration.instance
43+
end
44+
3745
def primary_key
3846
index.primary_key.to_sym
3947
end
48+
49+
def tidying?
50+
config.settings["real_time_tidy"]
51+
end
4052
end

lib/thinking_sphinx/real_time/populator.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def self.populate(index)
77

88
def initialize(index)
99
@index = index
10+
@started_at = Time.current
1011
end
1112

1213
def populate
@@ -17,12 +18,14 @@ def populate
1718
instrument 'populated', :instances => instances
1819
end
1920

21+
transcriber.clear_before(started_at) if configuration.settings["real_time_tidy"]
22+
2023
instrument 'finish_populating'
2124
end
2225

2326
private
2427

25-
attr_reader :index
28+
attr_reader :index, :started_at
2629

2730
delegate :controller, :batch_size, :to => :configuration
2831
delegate :scope, :to => :index

lib/thinking_sphinx/real_time/transcriber.rb

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ def initialize(index)
55
@index = index
66
end
77

8+
def clear_before(time)
9+
execute <<~SQL.strip
10+
DELETE FROM #{@index.name} WHERE sphinx_updated_at < #{time.to_i}
11+
SQL
12+
end
13+
814
def copy(*instances)
915
items = instances.select { |instance|
1016
instance.persisted? && copy?(instance)

lib/thinking_sphinx/real_time/translator.rb

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def initialize(object, column)
1010
end
1111

1212
def call
13+
return name.call(object) if name.is_a?(Proc)
1314
return name unless name.is_a?(Symbol)
1415
return result unless result.is_a?(String)
1516

lib/thinking_sphinx/settings.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ class ThinkingSphinx::Settings
1919
"binlog_path" => "tmp/binlog/ENVIRONMENT",
2020
"workers" => "threads",
2121
"mysql_encoding" => "utf8",
22-
"maximum_statement_length" => (2 ** 23) - 5
22+
"maximum_statement_length" => (2 ** 23) - 5,
23+
"real_time_tidy" => false
2324
}.freeze
2425

2526
def self.call(configuration)

spec/thinking_sphinx/real_time/index_spec.rb

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
describe ThinkingSphinx::RealTime::Index do
66
let(:index) { ThinkingSphinx::RealTime::Index.new :user }
77
let(:config) { double('config', :settings => {},
8-
:indices_location => 'location', :next_offset => 8) }
8+
:indices_location => 'location', :next_offset => 8,
9+
:index_set_class => index_set_class) }
10+
let(:index_set_class) { double(:index_set_class, :reference_name => :user) }
911

1012
before :each do
1113
allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
@@ -61,6 +63,16 @@
6163
it "has the internal deleted attribute by default" do
6264
expect(index.attributes.collect(&:name)).to include('sphinx_deleted')
6365
end
66+
67+
it "does not have an internal updated_at attribute by default" do
68+
expect(index.attributes.collect(&:name)).to_not include('sphinx_updated_at')
69+
end
70+
71+
it "has an internal updated_at attribute if real_time_tidy is true" do
72+
config.settings["real_time_tidy"] = true
73+
74+
expect(index.attributes.collect(&:name)).to include('sphinx_updated_at')
75+
end
6476
end
6577

6678
describe '#delta?' do

thinking-sphinx.gemspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $:.push File.expand_path('../lib', __FILE__)
55

66
Gem::Specification.new do |s|
77
s.name = 'thinking-sphinx'
8-
s.version = '5.1.0'
8+
s.version = '5.2.0'
99
s.platform = Gem::Platform::RUBY
1010
s.authors = ["Pat Allan"]
1111
s.email = ["[email protected]"]

0 commit comments

Comments
 (0)