Sha256: 78a57a115f00b028a173235f58720ab68cd8028f54205eac47ee7edfd13cc508

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

# frozen_string_literal: true

class ThinkingSphinx::Middlewares::StaleIdFilter <
  ThinkingSphinx::Middlewares::Middleware

  def call(contexts)
    @context   = contexts.first
    @stale_ids = []
    @retries   = stale_retries

    begin
      app.call contexts
    rescue ThinkingSphinx::Search::StaleIdsException => error
      raise error if @retries <= 0

      append_stale_ids error.ids, error.context
      ThinkingSphinx::Logger.log :message, log_message

      @retries -= 1 and retry
    end
  end

  private

  def append_stale_ids(ids, context)
    @stale_ids |= ids

    context.search.options[:without_ids] ||= []
    context.search.options[:without_ids] |= ids
  end

  def log_message
    'Stale Ids (%s %s left): %s' % [
      @retries, (@retries == 1 ? 'try' : 'tries'), @stale_ids.join(', ')
    ]
  end

  def stale_retries
    case context.search.options[:retry_stale]
    when nil, TrueClass
      2
    when FalseClass
      0
    else
      context.search.options[:retry_stale].to_i
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/middlewares/stale_id_filter.rb