<commit_before>
require 'base64'
# +SmartSessionStore+ is a session store that strives to correctly handle session storage in the face of multiple
# concurrent actions accessing the session. It is derived from <NAME>aes' +SqlSessionStore+, a stripped down,
# optimized for speed version of class +ActiveRecordStore+.
#
module SmartSessionStore

  class Store < ActionDispatch::Session::AbstractStore
    include SmartSessionStore::SessionSmarts
    
    # The class to be used for creating, retrieving and updating sessions.
    # Defaults to SmartSessionStore::Session, which is derived from +ActiveRecord::Base+.
    #
    # In order to achieve acceptable performance you should implement
    # your own session class, similar to the one provided for Myqsl.
    #
    # Only functions +find_session+, +create_session+,
    # +update_session+ and +destroy+ are required. See file +mysql_session.rb+.

    cattr_accessor :session_class
    @@session_class = SmartSessionStore::SqlSession

    SESSION_RECORD_KEY = 'rack.session.record'.freeze
      
    private
    
    def get_session(env, sid)
      ActiveRecord::Base.silence do
        sid ||= generate_sid
        session = find_session(sid)
        env[SESSION_RECORD_KEY] = session
        [sid, unmarshalize(session.data)]
      end
    end

    def set_session(env, sid, session_data)
      ActiveRecord::Base.silence do
        record = get_session_model(env, sid)

        data, session = save_session(record, session_data)
        env[SESSION_RECORD_KEY] = session
      end

      return sid
    end

    def get_session_model(env, sid)
      if env[ENV_SESSION_OPTIONS_KEY][:id].nil?
        env[SESSION_RECORD_KEY] = find_session(sid)
      else
        env[SESSION_RECORD_KEY] ||= find_session(sid)
      end
    end
    
    def find_session(id)
      @@session_class.find_session(id) ||
        @@session_class.create_session(id, marshalize({}))
    end
    
    # Rails 2.3.14 needs this
    def destroy(env)
      if (sid = current_session_id(env)).present? && session = find_session(sid)
        session.destroy
      end
    end
  end<commit_msg>this constant has moved into rack<commit_after>
require 'base64'
# +SmartSessionStore+ is a session store that strives to correctly handle session storage in the face of multiple
# concurrent actions accessing the session. It is derived from <NAME>aes' +SqlSessionStore+, a stripped down,
# optimized for speed version of class +ActiveRecordStore+.
#
module SmartSessionStore

  class Store < ActionDispatch::Session::AbstractStore
    include SmartSessionStore::SessionSmarts
    
    # The class to be used for creating, retrieving and updating sessions.
    # Defaults to SmartSessionStore::Session, which is derived from +ActiveRecord::Base+.
    #
    # In order to achieve acceptable performance you should implement
    # your own session class, similar to the one provided for Myqsl.
    #
    # Only functions +find_session+, +create_session+,
    # +update_session+ and +destroy+ are required. See file +mysql_session.rb+.

    cattr_accessor :session_class
    @@session_class = SmartSessionStore::SqlSession

    SESSION_RECORD_KEY = 'rack.session.record'.freeze
      
    private
    
    def get_session(env, sid)
      ActiveRecord::Base.silence do
        sid ||= generate_sid
        session = find_session(sid)
        env[SESSION_RECORD_KEY] = session
        [sid, unmarshalize(session.data)]
      end
    end

    def set_session(env, sid, session_data)
      ActiveRecord::Base.silence do
        record = get_session_model(env, sid)

        data, session = save_session(record, session_data)
        env[SESSION_RECORD_KEY] = session
      end

      return sid
    end

    def get_session_model(env, sid)
      if env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY][:id].nil?
        env[SESSION_RECORD_KEY] = find_session(sid)
      else
        env[SESSION_RECORD_KEY] ||= find_session(sid)
      end
    end
    
    def find_session(id)
      @@session_class.find_session(id) ||
        @@session_class.create_session(id, marshalize({}))
    end
    
    # Rails 2.3.14 needs this
    def destroy(env)
      if (sid = current_session_id(env)).present? && session = find_session(sid)
        session.destroy
      end
    end
  end
{'fraction_non_alphanumeric': 0.0831193088956339, 'fraction_numerical': 0.002801774457156199, 'mean_word_length': 3.18359375, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '797072', 'n_tokens_mistral': 1277, 'n_tokens_neox': 1216, 'n_words': 350}