thinking-sphinx 5.1.0 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6245e3b98964aeb5e2540fd59d908458ee5596ed3eb8a1210dee732d95a8e061
4
- data.tar.gz: 78e991ec45835c311bba7db38c6c1ba8d2c97fec02c448b6e63a667debeb90d9
3
+ metadata.gz: c14b609439492778ba5139bc3e75ffc17952a803c8d6f0d892eb76b7587da4cb
4
+ data.tar.gz: fe3ba9a0b8c1d081960ff9f988e5a8a61e094da07d0dccdf3854f9962af6da26
5
5
  SHA512:
6
- metadata.gz: 043e7a4c5670d5e2371e38c27be22d7dae0c762e16f4f7e9c020c7794200cb9ce5c3f0455e692bfb8dba4fb7a8b4aa47de88a7add179c81f6f4fb294bc4b6d9c
7
- data.tar.gz: 6800fe7314fff4316b347f71f216702cb340b7e6ca7df7a609b93b082375b86dba044ea06efcdb56b3f898a1647cedbd486dd833d82ed7ad1a5c8de8625fa81d
6
+ metadata.gz: 6642a48f92ce9b7040e05eb2552a6329492151114468bdf2b82f31f5a6875ba33fda5e190ec0a0220d8a058b69af25057f8ce5beead88ba8351aa8d63dfbb5c0
7
+ data.tar.gz: 89b8ee56a4915cd1db7bd761766c56d2586ae575028a0fae2924d73588c312eb9f9505d2d63272e275710d7b6be4f81c63445d0a320363bcb098d3f4686913ef
data/.circleci/config.yml CHANGED
@@ -28,7 +28,7 @@ workflows:
28
28
  debian: buster
29
29
  matrix:
30
30
  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' ]
32
32
  # - test:
33
33
  # database: postgresql
34
34
  # sphinx_version: 3.3.1
@@ -62,7 +62,7 @@ workflows:
62
62
  debian: buster
63
63
  matrix:
64
64
  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' ]
66
66
  - test:
67
67
  name: "Manticore 3.5.4 with PostgreSQL"
68
68
  database: postgresql
@@ -71,7 +71,7 @@ workflows:
71
71
  debian: buster
72
72
  matrix:
73
73
  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' ]
75
75
 
76
76
  jobs:
77
77
  test:
@@ -115,6 +115,8 @@ jobs:
115
115
  command: |
116
116
  if [ "<< parameters.ruby >>" == "2.7.2" ]; then
117
117
  export BUNDLER_VERSION=2.1.4
118
+ elif [ "<< parameters.ruby >>" == "3.0.0" ]; then
119
+ export BUNDLER_VERSION=2.1.4
118
120
  else
119
121
  export BUNDLER_VERSION=1.17.3
120
122
  fi
data/Appraisals CHANGED
@@ -15,18 +15,18 @@ appraise 'rails_5_0' do
15
15
  gem 'jdbc-mysql', '~> 5.1.36', :platform => :jruby
16
16
  gem 'activerecord-jdbcmysql-adapter', '~> 50.0', :platform => :jruby
17
17
  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
19
19
 
20
20
  appraise 'rails_5_1' do
21
21
  gem 'rails', '~> 5.1.0'
22
22
  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
24
24
 
25
25
  appraise 'rails_5_2' do
26
26
  gem 'rails', '~> 5.2.0'
27
27
  gem 'mysql2', '~> 0.5.0', :platform => :ruby
28
28
  gem 'pg', '~> 1.0', :platform => :ruby
29
- end if RUBY_PLATFORM != 'java'
29
+ end if RUBY_PLATFORM != 'java' && RUBY_VERSION.to_f < 3.0
30
30
 
31
31
  appraise 'rails_6_0' do
32
32
  gem 'rails', '~> 6.0.0'
data/CHANGELOG.markdown CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project (at least, from v3.0.0 onwards) are documented in this file.
4
4
 
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
+
5
19
  ## 5.1.0 - 2020-12-28
6
20
 
7
21
  [Release Notes](https://github.com/pat/thinking-sphinx/releases/tag/v5.1.0)
data/README.textile CHANGED
@@ -1,6 +1,6 @@
1
1
  h1. Thinking Sphinx
2
2
 
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.
4
4
 
5
5
  h2. Upgrading
6
6
 
@@ -14,7 +14,7 @@ It's a gem, so install it like you would any other gem. You will also need to sp
14
14
 
15
15
  <pre><code>gem 'mysql2', '~> 0.4', :platform => :ruby
16
16
  gem 'jdbc-mysql', '~> 5.1.35', :platform => :jruby
17
- gem 'thinking-sphinx', '~> 5.1'</code></pre>
17
+ gem 'thinking-sphinx', '~> 5.2'</code></pre>
18
18
 
19
19
  The MySQL gems mentioned are required for connecting to Sphinx, so please include it even when you're using PostgreSQL for your database.
20
20
 
@@ -29,18 +29,18 @@ h2. Requirements
29
29
  The current release of Thinking Sphinx works with the following versions of its dependencies:
30
30
 
31
31
  |_. 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 |
36
36
 
37
37
  It _might_ work with older versions of Ruby, but it's highly recommended to update to a supported release.
38
38
 
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.
40
40
 
41
41
  h3. Sphinx or Manticore
42
42
 
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+.
44
44
 
45
45
  h3. Rails and ActiveRecord
46
46
 
@@ -96,12 +96,15 @@ require 'thinking_sphinx/test'
96
96
  require 'thinking_sphinx/utf8'
97
97
  require 'thinking_sphinx/wildcard'
98
98
  # Extended
99
- require 'thinking_sphinx/active_record'
100
99
  require 'thinking_sphinx/deltas'
101
100
  require 'thinking_sphinx/distributed'
102
101
  require 'thinking_sphinx/logger'
103
102
  require 'thinking_sphinx/real_time'
104
103
 
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
106
109
 
107
110
  ThinkingSphinx.before_index_hooks << ThinkingSphinx::Hooks::GuardPresence
@@ -7,6 +7,7 @@ class ThinkingSphinx::Railtie < Rails::Railtie
7
7
 
8
8
  initializer 'thinking_sphinx.initialisation' do
9
9
  ActiveSupport.on_load(:active_record) do
10
+ require 'thinking_sphinx/active_record'
10
11
  ActiveRecord::Base.include ThinkingSphinx::ActiveRecord::Base
11
12
  end
12
13
 
@@ -16,6 +17,10 @@ class ThinkingSphinx::Railtie < Rails::Railtie
16
17
  Rails.root.join("app", "indices").to_s
17
18
  )
18
19
  end
20
+
21
+ Rails.application.config.eager_load_paths -=
22
+ ThinkingSphinx::Configuration.instance.index_paths
23
+ Rails.application.config.eager_load_paths.freeze
19
24
  end
20
25
  end
21
26
 
@@ -13,6 +13,10 @@ class ThinkingSphinx::RealTime::Index::Template
13
13
  add_attribute primary_key, :sphinx_internal_id, :bigint
14
14
  add_attribute class_column, :sphinx_internal_class, :string, :facet => true
15
15
  add_attribute 0, :sphinx_deleted, :integer
16
+
17
+ if tidying?
18
+ add_attribute -> (_) { Time.current.to_i }, :sphinx_updated_at, :timestamp
19
+ end
16
20
  end
17
21
 
18
22
  private
@@ -34,7 +38,15 @@ class ThinkingSphinx::RealTime::Index::Template
34
38
  [:class, :name]
35
39
  end
36
40
 
41
+ def config
42
+ ThinkingSphinx::Configuration.instance
43
+ end
44
+
37
45
  def primary_key
38
46
  index.primary_key.to_sym
39
47
  end
48
+
49
+ def tidying?
50
+ config.settings["real_time_tidy"]
51
+ end
40
52
  end
@@ -7,6 +7,7 @@ class ThinkingSphinx::RealTime::Populator
7
7
 
8
8
  def initialize(index)
9
9
  @index = index
10
+ @started_at = Time.current
10
11
  end
11
12
 
12
13
  def populate
@@ -17,12 +18,14 @@ class ThinkingSphinx::RealTime::Populator
17
18
  instrument 'populated', :instances => instances
18
19
  end
19
20
 
21
+ transcriber.clear_before(started_at) if configuration.settings["real_time_tidy"]
22
+
20
23
  instrument 'finish_populating'
21
24
  end
22
25
 
23
26
  private
24
27
 
25
- attr_reader :index
28
+ attr_reader :index, :started_at
26
29
 
27
30
  delegate :controller, :batch_size, :to => :configuration
28
31
  delegate :scope, :to => :index
@@ -5,6 +5,12 @@ class ThinkingSphinx::RealTime::Transcriber
5
5
  @index = index
6
6
  end
7
7
 
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
+
8
14
  def copy(*instances)
9
15
  items = instances.select { |instance|
10
16
  instance.persisted? && copy?(instance)
@@ -10,6 +10,7 @@ class ThinkingSphinx::RealTime::Translator
10
10
  end
11
11
 
12
12
  def call
13
+ return name.call(object) if name.is_a?(Proc)
13
14
  return name unless name.is_a?(Symbol)
14
15
  return result unless result.is_a?(String)
15
16
 
@@ -19,7 +19,8 @@ class ThinkingSphinx::Settings
19
19
  "binlog_path" => "tmp/binlog/ENVIRONMENT",
20
20
  "workers" => "threads",
21
21
  "mysql_encoding" => "utf8",
22
- "maximum_statement_length" => (2 ** 23) - 5
22
+ "maximum_statement_length" => (2 ** 23) - 5,
23
+ "real_time_tidy" => false
23
24
  }.freeze
24
25
 
25
26
  def self.call(configuration)
@@ -5,7 +5,9 @@ require 'spec_helper'
5
5
  describe ThinkingSphinx::RealTime::Index do
6
6
  let(:index) { ThinkingSphinx::RealTime::Index.new :user }
7
7
  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) }
9
11
 
10
12
  before :each do
11
13
  allow(ThinkingSphinx::Configuration).to receive_messages :instance => config
@@ -61,6 +63,16 @@ describe ThinkingSphinx::RealTime::Index do
61
63
  it "has the internal deleted attribute by default" do
62
64
  expect(index.attributes.collect(&:name)).to include('sphinx_deleted')
63
65
  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
64
76
  end
65
77
 
66
78
  describe '#delta?' do
@@ -5,7 +5,7 @@ $:.push File.expand_path('../lib', __FILE__)
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = 'thinking-sphinx'
8
- s.version = '5.1.0'
8
+ s.version = '5.2.0'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Pat Allan"]
11
11
  s.email = ["pat@freelancing-gods.com"]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thinking-sphinx
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pat Allan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-28 00:00:00.000000000 Z
11
+ date: 2021-06-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord