Sha256: 5eb24b6e530f08399d95adf3948ac6b836968caf75f4489f06f42c32cb8de3fd

Contents?: true

Size: 611 Bytes

Versions: 11

Compression:

Stored size: 611 Bytes

Contents

require "faraday"

module Searchkick
  class Middleware < Faraday::Middleware
    def call(env)
      path = env[:url].path.to_s
      if path.end_with?("/_search")
        env[:request][:timeout] = Searchkick.search_timeout
      elsif path.end_with?("/_msearch")
        # assume no concurrent searches for timeout for now
        searches = env[:request_body].count("\n") / 2
        # do not allow timeout to exceed Searchkick.timeout
        timeout = [Searchkick.search_timeout * searches, Searchkick.timeout].min
        env[:request][:timeout] = timeout
      end
      @app.call(env)
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
searchkick-5.4.0 lib/searchkick/middleware.rb
searchkick-5.3.1 lib/searchkick/middleware.rb
searchkick-5.3.0 lib/searchkick/middleware.rb
searchkick-5.2.4 lib/searchkick/middleware.rb
searchkick-5.2.3 lib/searchkick/middleware.rb
searchkick-5.2.2 lib/searchkick/middleware.rb
searchkick-5.2.1 lib/searchkick/middleware.rb
searchkick-5.2.0 lib/searchkick/middleware.rb
searchkick-5.1.2 lib/searchkick/middleware.rb
searchkick-5.1.1 lib/searchkick/middleware.rb
searchkick-5.1.0 lib/searchkick/middleware.rb