diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-16 05:52:12 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2007-03-16 05:52:12 +0000 |
commit | 814dd007e51f34299b767528f5dfc36cb4b69be3 (patch) | |
tree | 961e072be5904c833539cce981b3c4011e19b499 /actionpack/lib/action_controller/cgi_ext | |
parent | f596dda0bb94fc97f4df165978f2bb1e40749645 (diff) | |
download | rails-814dd007e51f34299b767528f5dfc36cb4b69be3.tar.gz rails-814dd007e51f34299b767528f5dfc36cb4b69be3.tar.bz2 rails-814dd007e51f34299b767528f5dfc36cb4b69be3.zip |
Performance: patch cgi/session/pstore to require digest/md5 once rather than per #initialize. Closes #7583.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6431 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib/action_controller/cgi_ext')
-rw-r--r-- | actionpack/lib/action_controller/cgi_ext/pstore_performance_fix.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/cgi_ext/pstore_performance_fix.rb b/actionpack/lib/action_controller/cgi_ext/pstore_performance_fix.rb new file mode 100644 index 0000000000..ad08fbe7bf --- /dev/null +++ b/actionpack/lib/action_controller/cgi_ext/pstore_performance_fix.rb @@ -0,0 +1,30 @@ +# CGI::Session::Pstore.initialize requires 'digest/md5' on every call. +# This makes sense when spawning processes per request, but is +# unnecessarily expensive when serving requests from a long-lived +# process. +require 'cgi/session' +require 'cgi/session/pstore' +require 'digest/md5' + +class CGI::Session::Pstore #:nodoc: + def initialize(session, option={}) + dir = option['tmpdir'] || Dir::tmpdir + prefix = option['prefix'] || '' + id = session.session_id + md5 = Digest::MD5.hexdigest(id)[0,16] + path = dir+"/"+prefix+md5 + path.untaint + if File::exist?(path) + @hash = nil + else + unless session.new_session + raise CGI::Session::NoSession, "uninitialized session" + end + @hash = {} + end + @p = ::PStore.new(path) + @p.transaction do |p| + File.chmod(0600, p.path) + end + end +end |