ts-delayed-delta 1.1.2 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +25 -0
- data/.travis.yml +16 -0
- data/Gemfile +5 -0
- data/README.textile +7 -4
- data/Rakefile +23 -0
- data/VERSION +1 -0
- data/features/support/env.rb +15 -3
- data/lib/thinking_sphinx/deltas/delayed_delta.rb +16 -14
- data/lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb +16 -16
- data/lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb +13 -13
- data/lib/thinking_sphinx/deltas/delayed_delta/job.rb +2 -1
- data/lib/thinking_sphinx/deltas/delayed_delta/railtie.rb +5 -0
- data/lib/thinking_sphinx/deltas/delayed_delta/tasks.rb +4 -2
- data/lib/thinking_sphinx/deltas/delayed_delta/version.rb +5 -0
- data/lib/ts-delayed-delta.rb +4 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +4 -3
- data/spec/thinking_sphinx/deltas/delayed_delta/delta_job_spec.rb +14 -14
- data/spec/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job_spec.rb +21 -21
- data/spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb +13 -13
- data/spec/thinking_sphinx/deltas/delayed_delta_spec.rb +36 -36
- data/tasks/rails.rake +1 -0
- data/ts-delayed-delta.gemspec +30 -0
- metadata +92 -46
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
## MAC OS
|
2
|
+
.DS_Store
|
3
|
+
|
4
|
+
## TEXTMATE
|
5
|
+
*.tmproj
|
6
|
+
tmtags
|
7
|
+
|
8
|
+
## EMACS
|
9
|
+
*~
|
10
|
+
\#*
|
11
|
+
.\#*
|
12
|
+
|
13
|
+
## VIM
|
14
|
+
*.swp
|
15
|
+
|
16
|
+
## PROJECT::GENERAL
|
17
|
+
coverage
|
18
|
+
rdoc
|
19
|
+
pkg
|
20
|
+
Gemfile.lock
|
21
|
+
|
22
|
+
## PROJECT::SPECIFIC
|
23
|
+
features/thinking_sphinx/database.yml
|
24
|
+
tmp
|
25
|
+
.bundle
|
data/.travis.yml
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
rvm:
|
2
|
+
# - 1.8.6
|
3
|
+
- 1.8.7
|
4
|
+
- 1.9.2
|
5
|
+
- 1.9.3
|
6
|
+
- rbx
|
7
|
+
- rbx-2.0
|
8
|
+
- ree
|
9
|
+
# - jruby
|
10
|
+
# - ruby-head
|
11
|
+
# env:
|
12
|
+
# - SPHINX_BIN=/usr/local/sphinx-0.9.9/bin SPHINX_VERSION=0.9.9
|
13
|
+
# - SPHINX_BIN=/usr/local/sphinx-1.10/bin SPHINX_VERSION=1.10
|
14
|
+
# - SPHINX_BIN=/usr/local/sphinx-2.0.1/bin SPHINX_VERSION=2.0.1
|
15
|
+
before_script:
|
16
|
+
- "mysql -e 'create database thinking_sphinx;' > /dev/null"
|
data/Gemfile
ADDED
data/README.textile
CHANGED
@@ -13,7 +13,7 @@ In your @environment.rb@ file, with the rest of your gem dependencies:
|
|
13
13
|
:version => '>= 1.0.0',
|
14
14
|
:source => 'http://gemcutter.org'</code></pre>
|
15
15
|
|
16
|
-
And add the following line to the bottom of your @Rakefile
|
16
|
+
And add the following line to the bottom of your @Rakefile@ if you're not using Rails 3 or newer:
|
17
17
|
|
18
18
|
<pre><code>require 'thinking_sphinx/deltas/delayed_delta/tasks'</code></pre>
|
19
19
|
|
@@ -21,15 +21,15 @@ If this is your first time running Delayed Job, then you're going to need the jo
|
|
21
21
|
|
22
22
|
<pre><code>script/generate delayed_job</code></pre>
|
23
23
|
|
24
|
-
For the
|
24
|
+
For the indices you want to use this delta approach, make sure you set that up in their @define_index@ blocks.
|
25
25
|
|
26
26
|
<pre><code>define_index do
|
27
27
|
# ...
|
28
|
-
|
28
|
+
|
29
29
|
set_property :delta => :delayed
|
30
30
|
end</code></pre>
|
31
31
|
|
32
|
-
If you've never used delta
|
32
|
+
If you've never used delta indices before, you'll want to add the boolean column named delta to each model that is using the approach.
|
33
33
|
|
34
34
|
<pre><code>def self.up
|
35
35
|
add_column :articles, :delta, :boolean, :default => true, :null => false
|
@@ -53,6 +53,9 @@ h2. Contributors
|
|
53
53
|
* "Alexander Simonov":http://simonov.me/ (Explicit table definition)
|
54
54
|
* "David Goodlad":http://david.goodlad.ca/ (Delayed Job/ActiveRecord load order fix)
|
55
55
|
* "Ben Hutton":http://www.benhutton.com/ (Delayed Job compatibility update)
|
56
|
+
* "Reinier de Lange":http://www.nedforce.nl/ (Fix for table name reference)
|
57
|
+
* "Enrico Brunetta":http://github.com/enrico (Adding Railtie for Rails 3)
|
58
|
+
* "Jonathan Viney":https://github.com/jviney and "James Healy":http://yob.id.au/ (Rails 3.2 deprecation fixes)
|
56
59
|
|
57
60
|
h2. Copyright
|
58
61
|
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
|
4
|
+
Bundler::GemHelper.install_tasks
|
5
|
+
Bundler.require :default, :development
|
6
|
+
|
7
|
+
require 'rspec/core/rake_task'
|
8
|
+
require 'cucumber/rake/task'
|
9
|
+
|
10
|
+
RSpec::Core::RakeTask.new
|
11
|
+
|
12
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
13
|
+
spec.rcov_opts = ['--exclude', 'spec', '--exclude', 'gems']
|
14
|
+
spec.rcov = true
|
15
|
+
end
|
16
|
+
|
17
|
+
Cucumber::Rake::Task.new do |task|
|
18
|
+
task.cucumber_opts = '--exclude features/thinking_sphinx'
|
19
|
+
end
|
20
|
+
|
21
|
+
YARD::Rake::YardocTask.new
|
22
|
+
|
23
|
+
task :default => [:spec, :cucumber]
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.1.2
|
data/features/support/env.rb
CHANGED
@@ -1,8 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
require 'cucumber'
|
3
|
-
require 'spec/expectations'
|
4
2
|
require 'fileutils'
|
3
|
+
require 'bundler'
|
4
|
+
|
5
|
+
Bundler.require :default, :development
|
6
|
+
|
5
7
|
require 'active_record'
|
8
|
+
require 'thinking_sphinx'
|
9
|
+
require 'delayed_job'
|
10
|
+
|
11
|
+
ActiveRecord::Base.send(:include, ThinkingSphinx::ActiveRecord)
|
12
|
+
Delayed::Worker.backend = :active_record
|
13
|
+
|
14
|
+
ActiveSupport::Inflector.inflections do |inflect|
|
15
|
+
inflect.plural /^(.*)beta$/i, '\1betas'
|
16
|
+
inflect.singular /^(.*)betas$/i, '\1beta'
|
17
|
+
end
|
6
18
|
|
7
19
|
$:.unshift File.dirname(__FILE__) + '/../../lib'
|
8
20
|
|
@@ -11,7 +23,7 @@ require 'cucumber/thinking_sphinx/internal_world'
|
|
11
23
|
# Time.zone_default = Time.__send__(:get_zone, 'Melbourne')
|
12
24
|
# ActiveRecord::Base.time_zone_aware_attributes = true
|
13
25
|
# ActiveRecord::Base.default_timezone = :utc
|
14
|
-
#
|
26
|
+
#
|
15
27
|
world = Cucumber::ThinkingSphinx::InternalWorld.new
|
16
28
|
world.configure_database
|
17
29
|
|
@@ -4,59 +4,61 @@ require 'thinking_sphinx'
|
|
4
4
|
require 'thinking_sphinx/deltas/delayed_delta/delta_job'
|
5
5
|
require 'thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job'
|
6
6
|
require 'thinking_sphinx/deltas/delayed_delta/job'
|
7
|
+
require 'thinking_sphinx/deltas/delayed_delta/version'
|
7
8
|
|
8
9
|
# Delayed Deltas for Thinking Sphinx, using Delayed Job.
|
9
|
-
#
|
10
|
+
#
|
10
11
|
# This documentation is aimed at those reading the code. If you're looking for
|
11
12
|
# a guide to Thinking Sphinx and/or deltas, I recommend you start with the
|
12
13
|
# Thinking Sphinx site instead - or the README for this library at the very
|
13
14
|
# least.
|
14
|
-
#
|
15
|
+
#
|
15
16
|
# @author Patrick Allan
|
16
17
|
# @see http://ts.freelancing-gods.com Thinking Sphinx
|
17
18
|
#
|
18
19
|
class ThinkingSphinx::Deltas::DelayedDelta < ThinkingSphinx::Deltas::DefaultDelta
|
19
|
-
|
20
|
+
|
20
21
|
# Adds a job to the queue for processing the given model's delta index. A job
|
21
22
|
# for hiding the instance in the core index is also created, if an instance is
|
22
23
|
# provided.
|
23
|
-
#
|
24
|
-
# Neither job will be queued if updates or deltas are disabled, or if the
|
24
|
+
#
|
25
|
+
# Neither job will be queued if updates or deltas are disabled, or if the
|
25
26
|
# instance (when given) is not toggled to be in the delta index. The first two
|
26
27
|
# options are controlled via ThinkingSphinx.updates_enabled? and
|
27
28
|
# ThinkingSphinx.deltas_enabled?.
|
28
|
-
#
|
29
|
+
#
|
29
30
|
# @param [Class] model the ActiveRecord model to index.
|
30
31
|
# @param [ActiveRecord::Base] instance the instance of the given model that
|
31
32
|
# has changed. Optional.
|
32
33
|
# @return [Boolean] true
|
33
|
-
#
|
34
|
+
#
|
34
35
|
def index(model, instance = nil)
|
35
36
|
return true if skip? instance
|
36
|
-
|
37
|
+
return true if instance && !toggled(instance)
|
38
|
+
|
37
39
|
ThinkingSphinx::Deltas::Job.enqueue(
|
38
40
|
ThinkingSphinx::Deltas::DeltaJob.new(model.delta_index_names),
|
39
41
|
ThinkingSphinx::Configuration.instance.delayed_job_priority
|
40
42
|
)
|
41
|
-
|
43
|
+
|
42
44
|
Delayed::Job.enqueue(
|
43
45
|
ThinkingSphinx::Deltas::FlagAsDeletedJob.new(
|
44
46
|
model.core_index_names, instance.sphinx_document_id
|
45
47
|
),
|
46
48
|
:priority => ThinkingSphinx::Configuration.instance.delayed_job_priority
|
47
49
|
) if instance
|
48
|
-
|
50
|
+
|
49
51
|
true
|
50
52
|
end
|
51
|
-
|
53
|
+
|
52
54
|
private
|
53
|
-
|
55
|
+
|
54
56
|
# Checks whether jobs should be enqueued. Only true if updates and deltas are
|
55
57
|
# enabled, and the instance (if there is one) is toggled.
|
56
|
-
#
|
58
|
+
#
|
57
59
|
# @param [ActiveRecord::Base, NilClass] instance
|
58
60
|
# @return [Boolean]
|
59
|
-
#
|
61
|
+
#
|
60
62
|
def skip?(instance)
|
61
63
|
!ThinkingSphinx.updates_enabled? ||
|
62
64
|
!ThinkingSphinx.deltas_enabled? ||
|
@@ -1,33 +1,33 @@
|
|
1
1
|
# A simple job class that processes a given index.
|
2
|
-
#
|
2
|
+
#
|
3
3
|
class ThinkingSphinx::Deltas::DeltaJob
|
4
|
-
attr_accessor :
|
5
|
-
|
4
|
+
attr_accessor :indices
|
5
|
+
|
6
6
|
# Initialises the object with an index name.
|
7
|
-
#
|
7
|
+
#
|
8
8
|
# @param [String] index the name of the Sphinx index
|
9
|
-
#
|
10
|
-
def initialize(
|
11
|
-
@
|
9
|
+
#
|
10
|
+
def initialize(indices)
|
11
|
+
@indices = indices
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# Shows index name in Delayed::Job#name.
|
15
|
-
#
|
15
|
+
#
|
16
16
|
def display_name
|
17
|
-
"#{self.class.name} for #{
|
17
|
+
"#{self.class.name} for #{indices.join(', ')}"
|
18
18
|
end
|
19
|
-
|
19
|
+
|
20
20
|
# Runs Sphinx's indexer tool to process the index. Currently assumes Sphinx is
|
21
21
|
# running.
|
22
|
-
#
|
22
|
+
#
|
23
23
|
# @return [Boolean] true
|
24
|
-
#
|
24
|
+
#
|
25
25
|
def perform
|
26
26
|
config = ThinkingSphinx::Configuration.instance
|
27
|
-
|
28
|
-
output = `#{config.bin_path}#{config.indexer_binary_name} --config #{config.config_file} --rotate #{
|
27
|
+
|
28
|
+
output = `#{config.bin_path}#{config.indexer_binary_name} --config "#{config.config_file}" --rotate #{indices.join(' ')}`
|
29
29
|
puts output unless ThinkingSphinx.suppress_delta_output?
|
30
|
-
|
30
|
+
|
31
31
|
true
|
32
32
|
end
|
33
33
|
end
|
@@ -1,32 +1,32 @@
|
|
1
1
|
# A simple job for flagging a specified Sphinx document in a given index as
|
2
2
|
# 'deleted'.
|
3
|
-
#
|
3
|
+
#
|
4
4
|
class ThinkingSphinx::Deltas::FlagAsDeletedJob
|
5
|
-
attr_accessor :
|
6
|
-
|
5
|
+
attr_accessor :indices, :document_id
|
6
|
+
|
7
7
|
# Initialises the object with an index name and document id. Please note that
|
8
8
|
# the document id is Sphinx's unique identifier, and will almost certainly not
|
9
9
|
# be the model instance's primary key value.
|
10
|
-
#
|
10
|
+
#
|
11
11
|
# @param [String] index The index name
|
12
12
|
# @param [Integer] document_id The document id
|
13
|
-
#
|
14
|
-
def initialize(
|
15
|
-
@
|
13
|
+
#
|
14
|
+
def initialize(indices, document_id)
|
15
|
+
@indices, @document_id = indices, document_id
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
# Updates the sphinx_deleted attribute for the given document, setting the
|
19
19
|
# value to 1 (true). This is not a special attribute in Sphinx, but is used
|
20
20
|
# by Thinking Sphinx to ignore deleted values between full re-indexing. It's
|
21
21
|
# particularly useful in this situation to avoid old values in the core index
|
22
22
|
# and just use the new values in the delta index as a reference point.
|
23
|
-
#
|
23
|
+
#
|
24
24
|
# @return [Boolean] true
|
25
|
-
#
|
25
|
+
#
|
26
26
|
def perform
|
27
27
|
config = ThinkingSphinx::Configuration.instance
|
28
|
-
|
29
|
-
|
28
|
+
|
29
|
+
indices.each do |index|
|
30
30
|
config.client.update(
|
31
31
|
index,
|
32
32
|
['sphinx_deleted'],
|
@@ -34,7 +34,7 @@ class ThinkingSphinx::Deltas::FlagAsDeletedJob
|
|
34
34
|
) if ThinkingSphinx.sphinx_running? &&
|
35
35
|
ThinkingSphinx.search_for_id(@document_id, index)
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
true
|
39
39
|
end
|
40
40
|
end
|
@@ -2,6 +2,7 @@ module Delayed
|
|
2
2
|
module Backend
|
3
3
|
module ActiveRecord
|
4
4
|
class Job < ::ActiveRecord::Base
|
5
|
+
self.table_name = "delayed_jobs"
|
5
6
|
end
|
6
7
|
end
|
7
8
|
end
|
@@ -14,7 +15,7 @@ end
|
|
14
15
|
# As such, this class should not be used for any other tasks.
|
15
16
|
#
|
16
17
|
class ThinkingSphinx::Deltas::Job < Delayed::Backend::ActiveRecord::Job
|
17
|
-
|
18
|
+
self.table_name = "delayed_jobs"
|
18
19
|
# Adds a job to the queue, if it doesn't already exist. This is to ensure
|
19
20
|
# multiple indexing requests for the same delta index don't get added, as the
|
20
21
|
# index only needs to be processed once.
|
@@ -1,13 +1,15 @@
|
|
1
1
|
namespace :thinking_sphinx do
|
2
2
|
task :index do
|
3
|
+
require 'thinking_sphinx/deltas/delayed_delta'
|
3
4
|
ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
|
4
5
|
end
|
5
|
-
|
6
|
+
|
6
7
|
desc "Process stored delta index requests"
|
7
8
|
task :delayed_delta => :app_env do
|
9
|
+
require 'delayed_job'
|
8
10
|
require 'delayed/worker'
|
9
11
|
require 'thinking_sphinx/deltas/delayed_delta'
|
10
|
-
|
12
|
+
|
11
13
|
Delayed::Worker.new(
|
12
14
|
:min_priority => ENV['MIN_PRIORITY'],
|
13
15
|
:max_priority => ENV['MAX_PRIORITY']
|
data/spec/spec.opts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/spec/spec_helper.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
|
2
2
|
|
3
3
|
require 'rubygems'
|
4
|
-
require '
|
5
|
-
|
4
|
+
require 'bundler'
|
5
|
+
|
6
|
+
Bundler.require :default, :development
|
6
7
|
|
7
8
|
require 'thinking_sphinx'
|
8
9
|
require 'thinking_sphinx/deltas/delayed_delta'
|
9
10
|
|
10
11
|
Delayed::Worker.backend = :active_record
|
11
12
|
|
12
|
-
|
13
|
+
RSpec.configure do |config|
|
13
14
|
#
|
14
15
|
end
|
@@ -1,40 +1,40 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Deltas::DeltaJob do
|
4
4
|
describe '#perform' do
|
5
5
|
before :each do
|
6
6
|
ThinkingSphinx.suppress_delta_output = false
|
7
|
-
|
7
|
+
|
8
8
|
@delta_job = ThinkingSphinx::Deltas::DeltaJob.new(['foo_core'])
|
9
9
|
@delta_job.stub! :` => true
|
10
10
|
@delta_job.stub! :puts => nil
|
11
11
|
end
|
12
|
-
|
12
|
+
|
13
13
|
it "should output the delta indexing by default" do
|
14
14
|
@delta_job.should_receive(:puts)
|
15
|
-
|
15
|
+
|
16
16
|
@delta_job.perform
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
it "should not output the delta indexing if requested" do
|
20
20
|
ThinkingSphinx.suppress_delta_output = true
|
21
21
|
@delta_job.should_not_receive(:puts)
|
22
|
-
|
22
|
+
|
23
23
|
@delta_job.perform
|
24
24
|
end
|
25
|
-
|
26
|
-
it "should process just the requested
|
25
|
+
|
26
|
+
it "should process just the requested indices" do
|
27
27
|
@delta_job.should_receive(:`) do |command|
|
28
28
|
command.should match(/foo_core/)
|
29
29
|
command.should_not match(/--all/)
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
@delta_job.perform
|
33
33
|
end
|
34
|
-
|
35
|
-
context 'multiple
|
36
|
-
it "should process all requested
|
37
|
-
@delta_job.
|
34
|
+
|
35
|
+
context 'multiple indices' do
|
36
|
+
it "should process all requested indices" do
|
37
|
+
@delta_job.indices = ['foo_core', 'bar_core']
|
38
38
|
@delta_job.should_receive(:`) do |command|
|
39
39
|
command.should match(/foo_core bar_core/)
|
40
40
|
end
|
@@ -45,7 +45,7 @@ describe ThinkingSphinx::Deltas::DeltaJob do
|
|
45
45
|
end
|
46
46
|
|
47
47
|
describe "#display_name" do
|
48
|
-
it "should display class name with all
|
48
|
+
it "should display class name with all indices" do
|
49
49
|
@delta_job = ThinkingSphinx::Deltas::DeltaJob.new(['foo_core', 'bar_core'])
|
50
50
|
@delta_job.display_name.should == "ThinkingSphinx::Deltas::DeltaJob for foo_core, bar_core"
|
51
51
|
end
|
@@ -1,77 +1,77 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Deltas::FlagAsDeletedJob do
|
4
4
|
describe '#perform' do
|
5
5
|
before :each do
|
6
6
|
ThinkingSphinx.updates_enabled = true
|
7
7
|
@client = stub('client', :update => true)
|
8
|
-
|
8
|
+
|
9
9
|
ThinkingSphinx::Configuration.instance.stub!(:client => @client)
|
10
10
|
ThinkingSphinx.stub!(:search_for_id => true)
|
11
11
|
ThinkingSphinx.stub!(:sphinx_running? => true)
|
12
|
-
|
12
|
+
|
13
13
|
@job = ThinkingSphinx::Deltas::FlagAsDeletedJob.new(['foo_core'], 12)
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
it "should not update if Sphinx isn't running" do
|
17
17
|
ThinkingSphinx.stub!(:sphinx_running? => false)
|
18
18
|
@client.should_not_receive(:update)
|
19
|
-
|
19
|
+
|
20
20
|
@job.perform
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it "should not update if the document isn't in the index" do
|
24
24
|
ThinkingSphinx.stub!(:search_for_id => false)
|
25
25
|
@client.should_not_receive(:update)
|
26
|
-
|
26
|
+
|
27
27
|
@job.perform
|
28
28
|
end
|
29
|
-
|
29
|
+
|
30
30
|
it "should update the specified index" do
|
31
31
|
@client.should_receive(:update) do |index, attributes, values|
|
32
32
|
index.should == 'foo_core'
|
33
33
|
end
|
34
|
-
|
34
|
+
|
35
35
|
@job.perform
|
36
36
|
end
|
37
|
-
|
38
|
-
it "should update all specified
|
39
|
-
@job.
|
37
|
+
|
38
|
+
it "should update all specified indices" do
|
39
|
+
@job.indices = ['foo_core', 'bar_core']
|
40
40
|
@client.should_receive(:update).with('foo_core', anything, anything)
|
41
41
|
@client.should_receive(:update).with('bar_core', anything, anything)
|
42
|
-
|
42
|
+
|
43
43
|
@job.perform
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
it "should update the sphinx_deleted attribute" do
|
47
47
|
@client.should_receive(:update) do |index, attributes, values|
|
48
48
|
attributes.should == ['sphinx_deleted']
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
@job.perform
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
it "should set sphinx_deleted for the given document to true" do
|
55
55
|
@client.should_receive(:update) do |index, attributes, values|
|
56
56
|
values[12].should == [1]
|
57
57
|
end
|
58
|
-
|
58
|
+
|
59
59
|
@job.perform
|
60
60
|
end
|
61
|
-
|
61
|
+
|
62
62
|
it "should check for the existence of the document in the specified index" do
|
63
63
|
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
|
64
64
|
index.should == 'foo_core'
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
@job.perform
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
it "should check for the existence of the given document id" do
|
71
71
|
ThinkingSphinx.should_receive(:search_for_id) do |id, index|
|
72
72
|
id.should == 12
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
@job.perform
|
76
76
|
end
|
77
77
|
end
|
@@ -1,51 +1,51 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Deltas::Job do
|
4
4
|
describe '.enqueue' do
|
5
5
|
before :each do
|
6
6
|
ThinkingSphinx::Deltas::Job.stub!(:count => 0)
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
it "should enqueue if there's no existing jobs for the same index" do
|
10
10
|
Delayed::Job.should_receive(:enqueue)
|
11
|
-
|
11
|
+
|
12
12
|
ThinkingSphinx::Deltas::Job.enqueue(stub('object'))
|
13
13
|
end
|
14
|
-
|
14
|
+
|
15
15
|
it "should not enqueue the job if there's an existing job already" do
|
16
16
|
ThinkingSphinx::Deltas::Job.stub!(:count => 1)
|
17
17
|
Delayed::Job.should_not_receive(:enqueue)
|
18
|
-
|
18
|
+
|
19
19
|
ThinkingSphinx::Deltas::Job.enqueue(stub('object'))
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
describe '.cancel_thinking_sphinx_jobs' do
|
24
24
|
before :each do
|
25
|
-
ThinkingSphinx::Deltas::Job.stub!(:connection
|
25
|
+
ThinkingSphinx::Deltas::Job.stub!(:connection => double('connection'))
|
26
26
|
ThinkingSphinx::Deltas::Job.stub!(:delete_all => true)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
it "should not delete any rows if the delayed_jobs table does not exist" do
|
30
30
|
ThinkingSphinx::Deltas::Job.connection.stub!(:tables => [])
|
31
31
|
ThinkingSphinx::Deltas::Job.should_not_receive(:delete_all)
|
32
|
-
|
32
|
+
|
33
33
|
ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
|
34
34
|
end
|
35
|
-
|
35
|
+
|
36
36
|
it "should delete rows if the delayed_jobs table does exist" do
|
37
37
|
ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
|
38
38
|
ThinkingSphinx::Deltas::Job.should_receive(:delete_all)
|
39
|
-
|
39
|
+
|
40
40
|
ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
it "should delete only Thinking Sphinx jobs" do
|
44
44
|
ThinkingSphinx::Deltas::Job.connection.stub!(:tables => ['delayed_jobs'])
|
45
45
|
ThinkingSphinx::Deltas::Job.should_receive(:delete_all) do |sql|
|
46
46
|
sql.should match(/handler LIKE '--- !ruby\/object:ThinkingSphinx::Deltas::\%'/)
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
ThinkingSphinx::Deltas::Job.cancel_thinking_sphinx_jobs
|
50
50
|
end
|
51
51
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe ThinkingSphinx::Deltas::DelayedDelta do
|
4
4
|
describe '#index' do
|
@@ -6,122 +6,122 @@ describe ThinkingSphinx::Deltas::DelayedDelta do
|
|
6
6
|
ThinkingSphinx.updates_enabled = true
|
7
7
|
ThinkingSphinx.deltas_enabled = true
|
8
8
|
ThinkingSphinx::Configuration.instance.delayed_job_priority = 2
|
9
|
-
|
9
|
+
|
10
10
|
ThinkingSphinx::Deltas::Job.stub!(:enqueue => true)
|
11
11
|
Delayed::Job.stub!(:enqueue => true, :inspect => "Delayed::Job")
|
12
|
-
|
12
|
+
|
13
13
|
@delayed_delta = ThinkingSphinx::Deltas::DelayedDelta.new(
|
14
14
|
stub('instance'), {}
|
15
15
|
)
|
16
16
|
@delayed_delta.stub!(:toggled => true)
|
17
|
-
|
17
|
+
|
18
18
|
@model = stub('foo')
|
19
19
|
@model.stub!(:name => 'foo')
|
20
20
|
@model.stub!(:source_of_sphinx_index => @model)
|
21
21
|
@model.stub!(:core_index_names => ['foo_core'])
|
22
22
|
@model.stub!(:delta_index_names => ['foo_delta'])
|
23
|
-
|
23
|
+
|
24
24
|
@instance = stub('instance')
|
25
25
|
@instance.stub!(:sphinx_document_id => 42)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
context 'updates disabled' do
|
29
29
|
before :each do
|
30
30
|
ThinkingSphinx.updates_enabled = false
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
it "should not enqueue a delta job" do
|
34
34
|
ThinkingSphinx::Deltas::Job.should_not_receive(:enqueue)
|
35
|
-
|
35
|
+
|
36
36
|
@delayed_delta.index(@model)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
39
|
it "should not enqueue a flag as deleted job" do
|
40
40
|
Delayed::Job.should_not_receive(:enqueue)
|
41
|
-
|
41
|
+
|
42
42
|
@delayed_delta.index(@model)
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
45
|
+
|
46
46
|
context 'deltas disabled' do
|
47
47
|
before :each do
|
48
48
|
ThinkingSphinx.deltas_enabled = false
|
49
49
|
end
|
50
|
-
|
50
|
+
|
51
51
|
it "should not enqueue a delta job" do
|
52
52
|
ThinkingSphinx::Deltas::Job.should_not_receive(:enqueue)
|
53
|
-
|
53
|
+
|
54
54
|
@delayed_delta.index(@model)
|
55
55
|
end
|
56
|
-
|
56
|
+
|
57
57
|
it "should not enqueue a flag as deleted job" do
|
58
58
|
Delayed::Job.should_not_receive(:enqueue)
|
59
|
-
|
59
|
+
|
60
60
|
@delayed_delta.index(@model)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
63
|
+
|
64
64
|
context "instance isn't toggled" do
|
65
65
|
before :each do
|
66
66
|
@delayed_delta.stub!(:toggled => false)
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
it "should not enqueue a delta job" do
|
70
70
|
ThinkingSphinx::Deltas::Job.should_not_receive(:enqueue)
|
71
|
-
|
71
|
+
|
72
72
|
@delayed_delta.index(@model, @instance)
|
73
73
|
end
|
74
|
-
|
74
|
+
|
75
75
|
it "should not enqueue a flag as deleted job" do
|
76
76
|
Delayed::Job.should_not_receive(:enqueue)
|
77
|
-
|
77
|
+
|
78
78
|
@delayed_delta.index(@model, @instance)
|
79
79
|
end
|
80
80
|
end
|
81
|
-
|
82
|
-
it "should enqueue a delta job for the appropriate
|
81
|
+
|
82
|
+
it "should enqueue a delta job for the appropriate indices" do
|
83
83
|
ThinkingSphinx::Deltas::Job.should_receive(:enqueue) do |job, priority|
|
84
|
-
job.
|
84
|
+
job.indices.should == ['foo_delta']
|
85
85
|
end
|
86
|
-
|
86
|
+
|
87
87
|
@delayed_delta.index(@model)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
it "should use the defined priority for the delta job" do
|
91
91
|
ThinkingSphinx::Deltas::Job.should_receive(:enqueue) do |job, priority|
|
92
92
|
priority.should == 2
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
@delayed_delta.index(@model)
|
96
96
|
end
|
97
|
-
|
98
|
-
it "should enqueue a flag-as-deleted job for the appropriate
|
97
|
+
|
98
|
+
it "should enqueue a flag-as-deleted job for the appropriate indices" do
|
99
99
|
Delayed::Job.should_receive(:enqueue) do |job, options|
|
100
|
-
job.
|
100
|
+
job.indices.should == ['foo_core']
|
101
101
|
end
|
102
|
-
|
102
|
+
|
103
103
|
@delayed_delta.index(@model, @instance)
|
104
104
|
end
|
105
|
-
|
105
|
+
|
106
106
|
it "should enqueue a flag-as-deleted job for the appropriate id" do
|
107
107
|
Delayed::Job.should_receive(:enqueue) do |job, options|
|
108
108
|
job.document_id.should == 42
|
109
109
|
end
|
110
|
-
|
110
|
+
|
111
111
|
@delayed_delta.index(@model, @instance)
|
112
112
|
end
|
113
|
-
|
113
|
+
|
114
114
|
it "should use the defined priority for the flag-as-deleted job" do
|
115
115
|
Delayed::Job.should_receive(:enqueue) do |job, options|
|
116
116
|
options[:priority].should == 2
|
117
117
|
end
|
118
|
-
|
118
|
+
|
119
119
|
@delayed_delta.index(@model, @instance)
|
120
120
|
end
|
121
|
-
|
121
|
+
|
122
122
|
it "should not enqueue a flag-as-deleted job if no instance is provided" do
|
123
123
|
Delayed::Job.should_not_receive(:enqueue)
|
124
|
-
|
124
|
+
|
125
125
|
@delayed_delta.index(@model)
|
126
126
|
end
|
127
127
|
end
|
data/tasks/rails.rake
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '/../lib/thinking_sphinx/deltas/delayed_delta/tasks')
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'thinking_sphinx/deltas/delayed_delta/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'ts-delayed-delta'
|
7
|
+
s.version = ThinkingSphinx::DelayedDelta::Version
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Pat Allan']
|
10
|
+
s.email = ['pat@freelancing-gods.com']
|
11
|
+
s.homepage = 'http://github.com/freelancing-god/ts-delayed-delta'
|
12
|
+
s.summary = %q{Thinking Sphinx - Delayed Deltas}
|
13
|
+
s.description = %q{Manage delta indexes via Delayed Job for Thinking Sphinx}
|
14
|
+
|
15
|
+
s.rubyforge_project = 'ts-delayed-delta'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ['lib']
|
21
|
+
|
22
|
+
s.add_runtime_dependency 'thinking-sphinx', '>= 1.3.6'
|
23
|
+
s.add_runtime_dependency 'delayed_job', '>= 2.0.4'
|
24
|
+
|
25
|
+
s.add_development_dependency 'mysql2', '0.3.7'
|
26
|
+
s.add_development_dependency 'yard', '>= 0.7.2'
|
27
|
+
s.add_development_dependency 'rake', '>= 0.9.2'
|
28
|
+
s.add_development_dependency 'rspec', '2.6.0'
|
29
|
+
s.add_development_dependency 'cucumber', '1.0.2'
|
30
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ts-delayed-delta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 3
|
10
|
+
version: 1.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Pat Allan
|
@@ -15,12 +15,10 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2012-03-02 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
|
-
|
23
|
-
prerelease: false
|
21
|
+
type: :runtime
|
24
22
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
23
|
none: false
|
26
24
|
requirements:
|
@@ -32,85 +30,122 @@ dependencies:
|
|
32
30
|
- 3
|
33
31
|
- 6
|
34
32
|
version: 1.3.6
|
35
|
-
type: :runtime
|
36
33
|
version_requirements: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
38
|
-
name: delayed_job
|
39
34
|
prerelease: false
|
35
|
+
name: thinking-sphinx
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
type: :runtime
|
40
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
39
|
none: false
|
42
40
|
requirements:
|
43
41
|
- - ">="
|
44
42
|
- !ruby/object:Gem::Version
|
45
|
-
hash:
|
43
|
+
hash: 7
|
46
44
|
segments:
|
47
45
|
- 2
|
48
|
-
- 1
|
49
46
|
- 0
|
50
|
-
|
51
|
-
|
47
|
+
- 4
|
48
|
+
version: 2.0.4
|
52
49
|
version_requirements: *id002
|
53
|
-
- !ruby/object:Gem::Dependency
|
54
|
-
name: rspec
|
55
50
|
prerelease: false
|
51
|
+
name: delayed_job
|
52
|
+
- !ruby/object:Gem::Dependency
|
53
|
+
type: :development
|
56
54
|
requirement: &id003 !ruby/object:Gem::Requirement
|
57
55
|
none: false
|
58
56
|
requirements:
|
59
|
-
- - "
|
57
|
+
- - "="
|
60
58
|
- !ruby/object:Gem::Version
|
61
|
-
hash:
|
59
|
+
hash: 29
|
62
60
|
segments:
|
63
|
-
-
|
64
|
-
-
|
65
|
-
-
|
66
|
-
version:
|
67
|
-
type: :development
|
61
|
+
- 0
|
62
|
+
- 3
|
63
|
+
- 7
|
64
|
+
version: 0.3.7
|
68
65
|
version_requirements: *id003
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: yard
|
71
66
|
prerelease: false
|
67
|
+
name: mysql2
|
68
|
+
- !ruby/object:Gem::Dependency
|
69
|
+
type: :development
|
72
70
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
71
|
none: false
|
74
72
|
requirements:
|
75
73
|
- - ">="
|
76
74
|
- !ruby/object:Gem::Version
|
77
|
-
hash:
|
75
|
+
hash: 7
|
78
76
|
segments:
|
79
77
|
- 0
|
80
|
-
|
81
|
-
|
78
|
+
- 7
|
79
|
+
- 2
|
80
|
+
version: 0.7.2
|
82
81
|
version_requirements: *id004
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: cucumber
|
85
82
|
prerelease: false
|
83
|
+
name: yard
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
type: :development
|
86
86
|
requirement: &id005 !ruby/object:Gem::Requirement
|
87
87
|
none: false
|
88
88
|
requirements:
|
89
89
|
- - ">="
|
90
90
|
- !ruby/object:Gem::Version
|
91
|
-
hash:
|
91
|
+
hash: 63
|
92
92
|
segments:
|
93
93
|
- 0
|
94
|
-
|
95
|
-
|
94
|
+
- 9
|
95
|
+
- 2
|
96
|
+
version: 0.9.2
|
96
97
|
version_requirements: *id005
|
98
|
+
prerelease: false
|
99
|
+
name: rake
|
100
|
+
- !ruby/object:Gem::Dependency
|
101
|
+
type: :development
|
102
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
103
|
+
none: false
|
104
|
+
requirements:
|
105
|
+
- - "="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
hash: 23
|
108
|
+
segments:
|
109
|
+
- 2
|
110
|
+
- 6
|
111
|
+
- 0
|
112
|
+
version: 2.6.0
|
113
|
+
version_requirements: *id006
|
114
|
+
prerelease: false
|
115
|
+
name: rspec
|
116
|
+
- !ruby/object:Gem::Dependency
|
117
|
+
type: :development
|
118
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
119
|
+
none: false
|
120
|
+
requirements:
|
121
|
+
- - "="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
hash: 19
|
124
|
+
segments:
|
125
|
+
- 1
|
126
|
+
- 0
|
127
|
+
- 2
|
128
|
+
version: 1.0.2
|
129
|
+
version_requirements: *id007
|
130
|
+
prerelease: false
|
131
|
+
name: cucumber
|
97
132
|
description: Manage delta indexes via Delayed Job for Thinking Sphinx
|
98
|
-
email:
|
133
|
+
email:
|
134
|
+
- pat@freelancing-gods.com
|
99
135
|
executables: []
|
100
136
|
|
101
137
|
extensions: []
|
102
138
|
|
103
|
-
extra_rdoc_files:
|
104
|
-
|
105
|
-
- README.textile
|
139
|
+
extra_rdoc_files: []
|
140
|
+
|
106
141
|
files:
|
142
|
+
- .gitignore
|
143
|
+
- .travis.yml
|
144
|
+
- Gemfile
|
107
145
|
- LICENSE
|
108
146
|
- README.textile
|
109
|
-
-
|
110
|
-
-
|
111
|
-
- lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb
|
112
|
-
- lib/thinking_sphinx/deltas/delayed_delta/job.rb
|
113
|
-
- lib/thinking_sphinx/deltas/delayed_delta/tasks.rb
|
147
|
+
- Rakefile
|
148
|
+
- VERSION
|
114
149
|
- features/delayed_deltas.feature
|
115
150
|
- features/step_definitions/common_steps.rb
|
116
151
|
- features/step_definitions/delayed_delta_steps.rb
|
@@ -119,12 +154,22 @@ files:
|
|
119
154
|
- features/thinking_sphinx/db/fixtures/delayed_betas.rb
|
120
155
|
- features/thinking_sphinx/db/migrations/create_delayed_betas.rb
|
121
156
|
- features/thinking_sphinx/models/delayed_beta.rb
|
157
|
+
- lib/thinking_sphinx/deltas/delayed_delta.rb
|
158
|
+
- lib/thinking_sphinx/deltas/delayed_delta/delta_job.rb
|
159
|
+
- lib/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job.rb
|
160
|
+
- lib/thinking_sphinx/deltas/delayed_delta/job.rb
|
161
|
+
- lib/thinking_sphinx/deltas/delayed_delta/railtie.rb
|
162
|
+
- lib/thinking_sphinx/deltas/delayed_delta/tasks.rb
|
163
|
+
- lib/thinking_sphinx/deltas/delayed_delta/version.rb
|
164
|
+
- lib/ts-delayed-delta.rb
|
165
|
+
- spec/spec.opts
|
122
166
|
- spec/spec_helper.rb
|
123
167
|
- spec/thinking_sphinx/deltas/delayed_delta/delta_job_spec.rb
|
124
168
|
- spec/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job_spec.rb
|
125
169
|
- spec/thinking_sphinx/deltas/delayed_delta/job_spec.rb
|
126
170
|
- spec/thinking_sphinx/deltas/delayed_delta_spec.rb
|
127
|
-
|
171
|
+
- tasks/rails.rake
|
172
|
+
- ts-delayed-delta.gemspec
|
128
173
|
homepage: http://github.com/freelancing-god/ts-delayed-delta
|
129
174
|
licenses: []
|
130
175
|
|
@@ -153,8 +198,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
153
198
|
version: "0"
|
154
199
|
requirements: []
|
155
200
|
|
156
|
-
rubyforge_project:
|
157
|
-
rubygems_version: 1.
|
201
|
+
rubyforge_project: ts-delayed-delta
|
202
|
+
rubygems_version: 1.8.16
|
158
203
|
signing_key:
|
159
204
|
specification_version: 3
|
160
205
|
summary: Thinking Sphinx - Delayed Deltas
|
@@ -167,6 +212,7 @@ test_files:
|
|
167
212
|
- features/thinking_sphinx/db/fixtures/delayed_betas.rb
|
168
213
|
- features/thinking_sphinx/db/migrations/create_delayed_betas.rb
|
169
214
|
- features/thinking_sphinx/models/delayed_beta.rb
|
215
|
+
- spec/spec.opts
|
170
216
|
- spec/spec_helper.rb
|
171
217
|
- spec/thinking_sphinx/deltas/delayed_delta/delta_job_spec.rb
|
172
218
|
- spec/thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job_spec.rb
|