Permalink
Browse files

Speed improvement for session_options. #2287. [skaes@web.de]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2527 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 9025e5d commit 0efeeba7802b3e5137cd62cbb6fcf303a8a238a2 @jamis jamis committed Oct 11, 2005
Showing with 31 additions and 18 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +29 −18 actionpack/lib/action_controller/session_management.rb
View
@@ -1,5 +1,7 @@
*SVN*
+* Speed improvement for session_options. #2287. [skaes@web.de]
+
* Make cacheing binary files friendly with Windows. #1975. [Rich Olson]
* Convert boolean form options form the tag_helper. #809. [Michael Schuerig <michael@schuerig.de>]
@@ -77,26 +77,36 @@ def session(*args)
write_inheritable_array("session_options", [options])
end
+ def cached_session_options
+ @session_options ||= read_inheritable_attribute("session_options") || []
+ end
+
def session_options_for(request, action) #:nodoc:
- options = {}
+ if (session_options = cached_session_options).empty?
+ {}
+ else
+ options = {}
- action = action.to_s
- (read_inheritable_attribute("session_options") || []).each do |opts|
- next if opts[:if] && !opts[:if].call(request)
- if opts[:only] && opts[:only].include?(action)
- options.merge!(opts)
- elsif opts[:except] && !opts[:except].include?(action)
- options.merge!(opts)
- elsif !opts[:only] && !opts[:except]
- options.merge!(opts)
+ action = action.to_s
+ session_options.each do |opts|
+ next if opts[:if] && !opts[:if].call(request)
+ if opts[:only] && opts[:only].include?(action)
+ options.merge!(opts)
+ elsif opts[:except] && !opts[:except].include?(action)
+ options.merge!(opts)
+ elsif !opts[:only] && !opts[:except]
+ options.merge!(opts)
+ end
+ end
+
+ if options.empty? then options
+ else
+ options.delete :only
+ options.delete :except
+ options.delete :if
+ options[:disabled] ? false : options
end
end
-
- options.delete :only
- options.delete :except
- options.delete :if
-
- options[:disabled] ? false : options
end
end
@@ -108,8 +118,9 @@ def process_with_session_management_support(request, response, method = :perform
private
def clear_persistant_model_associations #:doc:
- session = @session.instance_variable_get("@data")
- session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) } if session
+ if session = @session.instance_variable_get("@data")
+ session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) }
+ end
end
end
end

0 comments on commit 0efeeba

Please sign in to comment.