diff options
author | José Valim <jose.valim@gmail.com> | 2010-06-25 12:14:59 +0200 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-06-25 12:15:17 +0200 |
commit | 21c99e93883c1cf32474ad65a507e69e373a380c (patch) | |
tree | 48edb175c5097a9320441a268e76363218527992 /actionpack/lib/action_dispatch/middleware/session | |
parent | 518b16d9aedf4534b11aab8043d4efd0361fa1fd (diff) | |
download | rails-21c99e93883c1cf32474ad65a507e69e373a380c.tar.gz rails-21c99e93883c1cf32474ad65a507e69e373a380c.tar.bz2 rails-21c99e93883c1cf32474ad65a507e69e373a380c.zip |
Calling exists? in the session store, without checking for stale sessions, 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.
Diffstat (limited to 'actionpack/lib/action_dispatch/middleware/session')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/session/cookie_store.rb | 15 |
2 files changed, 10 insertions, 10 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index fcc2287279..e9e0c26c73 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -88,7 +88,10 @@ module ActionDispatch 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? diff --git a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb index 6c1567f470..7ebd532f4a 100644 --- a/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/cookie_store.rb @@ -62,11 +62,12 @@ module ActionDispatch 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 @@ -78,10 +79,6 @@ module ActionDispatch 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 |