ryansch-ts-resque-delta 1.1.5.1 → 1.1.5.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  When /^I run the smart indexer$/ do
2
- ThinkingSphinx::Deltas::ResqueDelta::CoreIndex.new.smart_index
2
+ ThinkingSphinx::Deltas::ResqueDelta::CoreIndex.new.smart_index(:verbose => false)
3
3
  end
@@ -42,10 +42,13 @@ class ThinkingSphinx::Deltas::ResqueDelta::CoreIndex
42
42
  # Public: Index all indices while locking each delta as we index the corresponding core index.
43
43
  #
44
44
  # Returns true on success; false on failure.
45
- def smart_index
45
+ def smart_index(opts = {})
46
+ verbose = opts.fetch(:verbose, true)
47
+ verbose = false if ENV['SILENT'] == 'true'
48
+
46
49
  # Load config like ts:in.
47
50
  unless ENV['INDEX_ONLY'] == 'true'
48
- puts "Generating Configuration to #{ts_config.config_file}"
51
+ puts "Generating Configuration to #{ts_config.config_file}" if verbose
49
52
  ts_config.build
50
53
  end
51
54
  FileUtils.mkdir_p(ts_config.searchd_file_path)
@@ -56,7 +59,7 @@ class ThinkingSphinx::Deltas::ResqueDelta::CoreIndex
56
59
 
57
60
  with_delta_index_lock(index_name) do
58
61
  ThinkingSphinx::Deltas::ResqueDelta.prepare_for_core_index(index_name)
59
- ts_config.controller.index("#{index_name}_core", :verbose => true)
62
+ ts_config.controller.index("#{index_name}_core", :verbose => verbose)
60
63
  ret = $?
61
64
  end
62
65
 
@@ -30,15 +30,17 @@ class ThinkingSphinx::Deltas::ResqueDelta::DeltaJob
30
30
  # Get the document ids we've saved
31
31
  flag_as_deleted_ids = ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.processing_members(index)
32
32
 
33
- # Filter out the ids that aren't present in sphinx
34
- flag_as_deleted_ids = ThinkingSphinx::Search.bundle_searches(flag_as_deleted_ids) do |sphinx, id|
35
- sphinx.search_for_ids([], :index => index, :id_range => id..id)
36
- end.map(&:to_a).flatten
33
+ unless flag_as_deleted_ids.empty?
34
+ # Filter out the ids that aren't present in sphinx
35
+ flag_as_deleted_ids = filter_flag_as_deleted_ids(flag_as_deleted_ids, index)
37
36
 
38
- # Each hash element should be of the form { id => [1] }
39
- flag_hash = Hash[*flag_as_deleted_ids.collect {|id| [id, [1]] }.flatten(1)]
37
+ unless flag_as_deleted_ids.empty?
38
+ # Each hash element should be of the form { id => [1] }
39
+ flag_hash = Hash[*flag_as_deleted_ids.collect {|id| [id, [1]] }.flatten(1)]
40
40
 
41
- config.client.update(index, ['sphinx_deleted'], flag_hash)
41
+ config.client.update(index, ['sphinx_deleted'], flag_hash)
42
+ end
43
+ end
42
44
  end
43
45
 
44
46
  # Try again later if lock is in use.
@@ -87,4 +89,10 @@ class ThinkingSphinx::Deltas::ResqueDelta::DeltaJob
87
89
  def self.skip?(index)
88
90
  ThinkingSphinx::Deltas::ResqueDelta.locked?(index)
89
91
  end
92
+
93
+ def self.filter_flag_as_deleted_ids(ids, index)
94
+ ThinkingSphinx.search_for_ids(
95
+ :with => {:@id => ids}, :index => index
96
+ ).results[:matches].collect { |match| match[:doc] }
97
+ end
90
98
  end
@@ -1,7 +1,7 @@
1
1
  module ThinkingSphinx
2
2
  module Deltas
3
3
  class ResqueDeltaInfo
4
- VERSION = "1.1.5.1"
4
+ VERSION = "1.1.5.2"
5
5
  end
6
6
  end
7
7
  end
@@ -111,6 +111,7 @@ describe ThinkingSphinx::Deltas::ResqueDelta::CoreIndex do
111
111
 
112
112
  it 'should not generate sphinx configuration if INDEX_ONLY is true' do
113
113
  ENV.stub(:[]).with('INDEX_ONLY').and_return('true')
114
+ ENV.stub(:[]).with('SILENT').and_return(nil)
114
115
  config.should_not_receive(:build)
115
116
 
116
117
  subject.smart_index
@@ -118,6 +119,7 @@ describe ThinkingSphinx::Deltas::ResqueDelta::CoreIndex do
118
119
 
119
120
  it 'should generate sphinx configuration if INDEX_ONLY is not true' do
120
121
  ENV.stub(:[]).with('INDEX_ONLY').and_return(nil)
122
+ ENV.stub(:[]).with('SILENT').and_return(nil)
121
123
  config.should_receive(:build).once
122
124
 
123
125
  subject.smart_index
@@ -12,6 +12,7 @@ describe ThinkingSphinx::Deltas::ResqueDelta::DeltaJob do
12
12
  before :each do
13
13
  ThinkingSphinx.suppress_delta_output = false
14
14
  ThinkingSphinx::Deltas::ResqueDelta.stub(:locked?).and_return(false)
15
+ ThinkingSphinx.stub(:sphinx_running? => false)
15
16
  end
16
17
 
17
18
  it "should output the delta indexing by default" do
@@ -54,7 +55,6 @@ describe ThinkingSphinx::Deltas::ResqueDelta::DeltaJob do
54
55
  context 'with flag as deleted document ids' do
55
56
  let(:client) { stub('client', :update => true) }
56
57
  let(:document_ids) { [1, 2, 3] }
57
- let(:bundled_search) { double('bundled_search', :search_for_ids => []) }
58
58
 
59
59
  before :each do
60
60
  ThinkingSphinx.updates_enabled = true
@@ -63,7 +63,7 @@ describe ThinkingSphinx::Deltas::ResqueDelta::DeltaJob do
63
63
  ThinkingSphinx.stub(:sphinx_running? => true)
64
64
 
65
65
  ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedSet.stub(:processing_members => document_ids)
66
- ThinkingSphinx::Search.stub_chain(:bundle_searches, :map => document_ids)
66
+ subject.stub(:filter_flag_as_deleted_ids => document_ids)
67
67
  end
68
68
 
69
69
  it 'should get the processing set of flag as deleted document ids' do
@@ -78,22 +78,14 @@ describe ThinkingSphinx::Deltas::ResqueDelta::DeltaJob do
78
78
  end
79
79
 
80
80
  it "should validate the document ids with sphinx" do
81
- ThinkingSphinx::Search.stub(:bundle_searches).tap do |s|
82
- document_ids.inject(s) do |s, id|
83
- s.and_yield(bundled_search, id)
84
- end
85
- end
86
-
87
- document_ids.each do |id|
88
- bundled_search.should_receive(:search_for_ids).with([], :index => 'foo_core', :id_range => id..id)
89
- end
81
+ subject.should_receive(:filter_flag_as_deleted_ids).with(document_ids, 'foo_core')
90
82
 
91
83
  subject.perform('foo_delta')
92
84
  end
93
85
 
94
86
  context "with invalid ids" do
95
87
  before :each do
96
- ThinkingSphinx::Search.stub_chain(:bundle_searches, :map => document_ids.reject {|x| x == 2} )
88
+ subject.stub(:filter_flag_as_deleted_ids => document_ids.reject {|x| x == 2} )
97
89
  end
98
90
 
99
91
  it "should not update documents that aren't in the index" do
@@ -131,6 +123,15 @@ describe ThinkingSphinx::Deltas::ResqueDelta::DeltaJob do
131
123
  end
132
124
  subject.perform('foo_delta')
133
125
  end
126
+
127
+ context "without any ids" do
128
+ let(:document_ids) { [] }
129
+
130
+ it "should not validate the ids with sphinx" do
131
+ subject.should_not_receive(:filter_flag_as_deleted_ids)
132
+ subject.perform('foo_delta')
133
+ end
134
+ end
134
135
  end
135
136
  end
136
137
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ryansch-ts-resque-delta
3
3
  version: !ruby/object:Gem::Version
4
- hash: 65
4
+ hash: 71
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 1
9
9
  - 5
10
- - 1
11
- version: 1.1.5.1
10
+ - 2
11
+ version: 1.1.5.2
12
12
  platform: ruby
13
13
  authors:
14
14
  - Aaron Gibralter
@@ -17,7 +17,7 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2011-12-14 00:00:00 -08:00
20
+ date: 2011-12-15 00:00:00 -08:00
21
21
  default_executable:
22
22
  dependencies:
23
23
  - !ruby/object:Gem::Dependency