Sha256: ca53b1ae78f1cc7e627c3fef827feff738f37f065a39cb79b949ca46585467b6

Contents?: true

Size: 937 Bytes

Versions: 17

Compression:

Stored size: 937 Bytes

Contents

# frozen_string_literal: true

class ThinkingSphinx::Middlewares::StaleIdChecker <
  ThinkingSphinx::Middlewares::Middleware

  def call(contexts)
    contexts.each do |context|
      Inner.new(context).call
    end

    app.call contexts
  end

  private

  class Inner
    def initialize(context)
      @context = context
    end

    def call
      raise_exception if context[:results].any?(&:nil?)
    end

    private

    attr_reader :context

    def actual_ids
      context[:results].compact.collect(&:id)
    end

    def expected_ids
      context[:raw].collect { |row| row['sphinx_internal_id'].to_i }
    end

    def raise_exception
      raise ThinkingSphinx::Search::StaleIdsException.new(stale_ids, context)
    end

    def stale_ids
      # Currently only works with single-model queries. Has at no point done
      # otherwise, but such an improvement would be nice.
      expected_ids - actual_ids
    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_checker.rb
thinking-sphinx-5.5.1 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.5.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.4.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.3.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.2.1 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.2.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.1.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-5.0.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.4.1 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.4.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.3.2 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.3.1 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.3.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.2.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.1.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb
thinking-sphinx-4.0.0 lib/thinking_sphinx/middlewares/stale_id_checker.rb