Skip to content

Commit

Permalink
Calling exists? in the session store, without checking for stale sess…
Browse files Browse the repository at this point in the history
…ions, was causing the cookie store to panic because we need to unpack the whole session to get its key. This commit fixes this issue and also caches exists calls for performance improvements.
  • Loading branch information
josevalim committed Jun 25, 2010
1 parent 518b16d commit 21c99e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Expand Up @@ -88,7 +88,10 @@ def inspect
end

def exists?
@by.send(:exists?, @env)
return @exists if instance_variable_defined?(:@exists)
stale_session_check! do
@exists = @by.send(:exists?, @env)
end
end

def loaded?
Expand Down
Expand Up @@ -62,11 +62,12 @@ def extract_session_id(env)
end

def unpacked_cookie_data(env)
request = ActionDispatch::Request.new(env)
if data = request.cookie_jar.signed[@key]
data.stringify_keys!
else
{}
env["action_dispatch.request.unsigned_session_cookie"] ||= begin
request = ActionDispatch::Request.new(env)
if data = request.cookie_jar.signed[@key]
data.stringify_keys!
end
data || {}
end
end

Expand All @@ -78,10 +79,6 @@ def set_session(env, sid, session_data)
persistent_session_id!(session_data, sid)
end

def exists?(env)
ActionDispatch::Request.new(env).cookie_jar.key?(@key)
end

def destroy(env)
# session data is stored on client; nothing to do here
end
Expand Down

0 comments on commit 21c99e9

Please sign in to comment.