Sha256: 273ddd3ddb13ede782fc7da4d1b93d2e2f7c80dfd19852ec6a166b97ec83dace

Contents?: true

Size: 1.09 KB

Versions: 3

Compression:

Stored size: 1.09 KB

Contents

begin
  require 'delayed_job'
rescue LoadError
  raise "You must have delayed_job installed as a gem or plugin to use a delayed delta"
end

require 'thinking_sphinx/deltas/delayed_delta/delta_job'
require 'thinking_sphinx/deltas/delayed_delta/flag_as_deleted_job'
require 'thinking_sphinx/deltas/delayed_delta/job'

module ThinkingSphinx
  module Deltas
    class DelayedDelta < ThinkingSphinx::Deltas::DefaultDelta
      def index(model, instance = nil)
        return true unless ThinkingSphinx.updates_enabled? && ThinkingSphinx.deltas_enabled?
        return true if instance && !toggled(instance)
      
        ThinkingSphinx::Deltas::Job.enqueue(
          ThinkingSphinx::Deltas::DeltaJob.new(delta_index_name(model)),
          ThinkingSphinx::Configuration.instance.delayed_job_priority
        )
        
        Delayed::Job.enqueue(
          ThinkingSphinx::Deltas::FlagAsDeletedJob.new(
            core_index_name(model), instance.sphinx_document_id
          ),
          ThinkingSphinx::Configuration.instance.delayed_job_priority
        ) if instance
        
        true
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
moneypools-thinking-sphinx-1.2.13 lib/thinking_sphinx/deltas/delayed_delta.rb
moneypools-thinking-sphinx-1.2.12 lib/thinking_sphinx/deltas/delayed_delta.rb
moneypools-thinking-sphinx-1.2.11 lib/thinking_sphinx/deltas/delayed_delta.rb