diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index 880f5f6320..7b0ef65172 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Performance: patch cgi/session/pstore to require digest/md5 once rather than per #initialize. #7583 [Stefan Kaes] + * Undeprecate redirect_to with Hash argument and additional url_for parameters. #7837 [subelsky] * Cookie session store: ensure that new sessions doesn't reuse data from a deleted session in the same request. [Jeremy Kemper] 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 diff --git a/actionpack/lib/action_controller/cgi_process.rb b/actionpack/lib/action_controller/cgi_process.rb index 5712abc701..ddcc6003d0 100644 --- a/actionpack/lib/action_controller/cgi_process.rb +++ b/actionpack/lib/action_controller/cgi_process.rb @@ -2,6 +2,7 @@ require 'action_controller/cgi_ext/cgi_ext' require 'action_controller/cgi_ext/cookie_performance_fix' require 'action_controller/cgi_ext/raw_post_data_fix' require 'action_controller/cgi_ext/session_performance_fix' +require 'action_controller/cgi_ext/pstore_performance_fix' require 'action_controller/session/cookie_store' module ActionController #:nodoc: