ts-resque-delta 1.1.5 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +24 -0
- data/Guardfile +17 -0
- data/README.markdown +1 -0
- data/Rakefile +16 -4
- data/cucumber.yml +2 -0
- data/features/smart_indexing.feature +43 -0
- data/features/step_definitions/common_steps.rb +16 -3
- data/features/step_definitions/resque_delta_steps.rb +1 -1
- data/features/step_definitions/smart_indexing_steps.rb +3 -0
- data/features/support/env.rb +3 -4
- data/lib/thinking_sphinx/deltas/resque_delta.rb +32 -10
- data/lib/thinking_sphinx/deltas/resque_delta/core_index.rb +101 -0
- data/lib/thinking_sphinx/deltas/resque_delta/delta_job.rb +72 -10
- data/lib/thinking_sphinx/deltas/resque_delta/flag_as_deleted_set.rb +56 -0
- data/lib/thinking_sphinx/deltas/resque_delta/index_utils.rb +47 -0
- data/lib/thinking_sphinx/deltas/resque_delta/tasks.rb +4 -46
- data/lib/thinking_sphinx/deltas/resque_delta/version.rb +1 -1
- data/spec/spec_helper.rb +9 -5
- data/spec/thinking_sphinx/deltas/resque_delta/core_index_spec.rb +210 -0
- data/spec/thinking_sphinx/deltas/resque_delta/delta_job_spec.rb +138 -35
- data/spec/thinking_sphinx/deltas/resque_delta/flag_as_deleted_set_spec.rb +126 -0
- data/spec/thinking_sphinx/deltas/resque_delta/index_utils_spec.rb +67 -0
- data/spec/thinking_sphinx/deltas/resque_delta_spec.rb +126 -53
- data/ts-resque-delta.gemspec +8 -2
- metadata +185 -180
- data/features/support/redis_test_setup.rb +0 -23
- data/lib/thinking_sphinx/deltas/resque_delta/flag_as_deleted_job.rb +0 -30
- data/spec/spec.opts +0 -1
- data/spec/thinking_sphinx/deltas/resque_delta/flag_as_deleted_job_spec.rb +0 -66
- data/tasks/testing.rb +0 -20
@@ -1,23 +0,0 @@
|
|
1
|
-
module RedisTestSetup
|
2
|
-
|
3
|
-
def self.start_redis!(rails_root, env)
|
4
|
-
dir_temp = File.expand_path(File.join(rails_root, 'tmp'))
|
5
|
-
dir_conf = File.expand_path(File.join(rails_root, 'config'))
|
6
|
-
cwd = Dir.getwd
|
7
|
-
Dir.chdir(rails_root)
|
8
|
-
self.cleanup(dir_temp, env)
|
9
|
-
raise "unable to launch redis-server" unless system("redis-server #{dir_conf}/redis-#{env}.conf")
|
10
|
-
Dir.chdir(cwd)
|
11
|
-
Kernel.at_exit do
|
12
|
-
if (pid = `cat #{dir_temp}/redis-#{env}.pid`.strip) =~ /^\d+$/
|
13
|
-
self.cleanup(dir_temp, env)
|
14
|
-
Process.kill("KILL", pid.to_i)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def self.cleanup(dir_temp, env)
|
20
|
-
`rm -f #{dir_temp}/redis-#{env}-dump.rdb`
|
21
|
-
`rm -f #{dir_temp}/redis-#{env}.pid`
|
22
|
-
end
|
23
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
# A simple job for flagging a specified Sphinx document in a given index as
|
2
|
-
# 'deleted'.
|
3
|
-
#
|
4
|
-
class ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob
|
5
|
-
|
6
|
-
@queue = :ts_delta
|
7
|
-
|
8
|
-
# Takes an index name and document id. Please note that the document id is
|
9
|
-
# Sphinx's unique identifier, and will almost certainly not be the model
|
10
|
-
# instance's primary key value. Updates the sphinx_deleted attribute for the
|
11
|
-
# given document, setting the value to 1 (true). This is not a special
|
12
|
-
# attribute in Sphinx, but is used by Thinking Sphinx to ignore deleted
|
13
|
-
# values between full re-indexing. It's particularly useful in this
|
14
|
-
# situation to avoid old values in the core index and just use the new
|
15
|
-
# values in the delta index as a reference point.
|
16
|
-
#
|
17
|
-
# @param [Array] indices An array of index names
|
18
|
-
# @param [Integer] document_id The document id
|
19
|
-
#
|
20
|
-
# @return [Boolean] true
|
21
|
-
#
|
22
|
-
def self.perform(indices, document_id)
|
23
|
-
config = ThinkingSphinx::Configuration.instance
|
24
|
-
indices.each do |index|
|
25
|
-
if ThinkingSphinx.sphinx_running? && ThinkingSphinx.search_for_id(document_id, index)
|
26
|
-
config.client.update(index, ['sphinx_deleted'], {document_id => [1]})
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/spec/spec.opts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
@@ -1,66 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob do
|
4
|
-
describe '.perform' do
|
5
|
-
before :each do
|
6
|
-
ThinkingSphinx.updates_enabled = true
|
7
|
-
@client = stub('client', :update => true)
|
8
|
-
ThinkingSphinx::Configuration.instance.stub(:client => @client)
|
9
|
-
ThinkingSphinx.stub(:search_for_id => true)
|
10
|
-
ThinkingSphinx.stub(:sphinx_running? => true)
|
11
|
-
end
|
12
|
-
|
13
|
-
it "should not update if Sphinx isn't running" do
|
14
|
-
ThinkingSphinx.stub(:sphinx_running? => false)
|
15
|
-
@client.should_not_receive(:update)
|
16
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should not update if the document isn't in the index" do
|
20
|
-
ThinkingSphinx.stub(:search_for_id => false)
|
21
|
-
@client.should_not_receive(:update)
|
22
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "should update the specified index" do
|
26
|
-
@client.should_receive(:update) do |index, attributes, values|
|
27
|
-
index.should == 'foo_core'
|
28
|
-
end
|
29
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
30
|
-
end
|
31
|
-
|
32
|
-
it "should update all specified indices" do
|
33
|
-
@client.should_receive(:update).with('foo_core', anything, anything)
|
34
|
-
@client.should_receive(:update).with('bar_core', anything, anything)
|
35
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core', 'bar_core'], 12)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "should update the sphinx_deleted attribute" do
|
39
|
-
@client.should_receive(:update) do |index, attributes, values|
|
40
|
-
attributes.should == ['sphinx_deleted']
|
41
|
-
end
|
42
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "should set sphinx_deleted for the given document to true" do
|
46
|
-
@client.should_receive(:update) do |index, attributes, values|
|
47
|
-
values[12].should == [1]
|
48
|
-
end
|
49
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should check for the existence of the document in the specified index" do
|
53
|
-
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
|
54
|
-
index.should == 'foo_core'
|
55
|
-
end
|
56
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "should check for the existence of the given document id" do
|
60
|
-
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
|
61
|
-
id.should == 12
|
62
|
-
end
|
63
|
-
ThinkingSphinx::Deltas::ResqueDelta::FlagAsDeletedJob.perform(['foo_core'], 12)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
data/tasks/testing.rb
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'spec/rake/spectask'
|
2
|
-
require 'cucumber/rake/task'
|
3
|
-
|
4
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
5
|
-
spec.libs << 'lib' << 'spec'
|
6
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
7
|
-
end
|
8
|
-
|
9
|
-
Spec::Rake::SpecTask.new(:rcov) do |spec|
|
10
|
-
spec.libs << 'lib' << 'spec'
|
11
|
-
spec.pattern = 'spec/**/*_spec.rb'
|
12
|
-
spec.rcov = true
|
13
|
-
end
|
14
|
-
|
15
|
-
Cucumber::Rake::Task.new do |task|
|
16
|
-
task.cucumber_opts = '--exclude features/thinking_sphinx'
|
17
|
-
end
|
18
|
-
|
19
|
-
task :spec
|
20
|
-
task :cucumber
|