Sha256: 028ca5ce30a3f6419559b4bbd46b196d420343a034c7673ec549e2639c1c9e19

Contents?: true

Size: 1.34 KB

Versions: 41

Compression:

Stored size: 1.34 KB

Contents

require 'monitor'
require File.join(File.dirname(__FILE__), 'abstract_session_proxy')

module Sunspot
  module SessionProxy
    # 
    # This class implements a session proxy that creates a different Session
    # object for each thread. Any multithreaded application should use this
    # proxy.
    #
    class ThreadLocalSessionProxy < AbstractSessionProxy
      FINALIZER = Proc.new do |object_id|
        Thread.current[:"sunspot_session_#{object_id}"] = nil
      end

      # The configuration with which the thread-local sessions are initialized.
      attr_reader :config
      @@next_id = 0

      delegate :batch, :commit, :commit_if_delete_dirty, :commit_if_dirty, :delete_dirty?, :dirty?, :index, :index!, :new_search, :optimize, :remove, :remove!, :remove_all, :remove_all!, :remove_by_id, :remove_by_id!, :search, :more_like_this, :new_more_like_this, :to => :session

      # 
      # Optionally pass an existing Sunspot::Configuration object. If none is
      # passed, a default configuration is used; it can then be modified using
      # the #config attribute.
      #
      def initialize(config = Sunspot::Configuration.new)
        @config = config
        ObjectSpace.define_finalizer(self, FINALIZER)
      end

      def session #:nodoc:
        Thread.current[:"sunspot_session_#{object_id}"] ||= Session.new(config)
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 9 rubygems

Version Path
sunspot-2.2.0 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.1.1 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.1.0 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0.pre.130115 lib/sunspot/session_proxy/thread_local_session_proxy.rb
gojee-sunspot-2.0.5 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0.pre.120925 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot_solr-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot_rails-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0.pre.120924 sunspot/lib/sunspot/session_proxy/thread_local_session_proxy.rb
gojee-sunspot-2.0.4 lib/sunspot/session_proxy/thread_local_session_proxy.rb
gojee-sunspot-2.0.2 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0.pre.120720 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-1.3.3 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-1.3.2 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0.pre.120417 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-2.0.0.pre.120415 lib/sunspot/session_proxy/thread_local_session_proxy.rb
sunspot-1.3.1 lib/sunspot/session_proxy/thread_local_session_proxy.rb
erichummel-sunspot-2.0.0.pre.111215d lib/sunspot/session_proxy/thread_local_session_proxy.rb
erichummel-sunspot-2.0.0.pre.111215c lib/sunspot/session_proxy/thread_local_session_proxy.rb