Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 2527

Show
Ignore:
Timestamp:
10/11/05 01:53:31 (3 years ago)
Author:
minam
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r2524 r2527  
    11*SVN* 
     2 
     3* Speed improvement for session_options. #2287. [skaes@web.de] 
    24 
    35* Make cacheing binary files friendly with Windows. #1975. [Rich Olson] 
  • trunk/actionpack/lib/action_controller/session_management.rb

    r2230 r2527  
    7878      end 
    7979 
     80      def cached_session_options 
     81        @session_options ||= read_inheritable_attribute("session_options") || [] 
     82      end 
     83 
    8084      def session_options_for(request, action) #:nodoc: 
    81         options = {} 
     85        if (session_options = cached_session_options).empty? 
     86          {} 
     87        else 
     88          options = {} 
    8289 
    83         action = action.to_s 
    84         (read_inheritable_attribute("session_options") || []).each do |opts| 
    85           next if opts[:if] && !opts[:if].call(request) 
    86           if opts[:only] && opts[:only].include?(action) 
    87             options.merge!(opts) 
    88           elsif opts[:except] && !opts[:except].include?(action) 
    89             options.merge!(opts) 
    90           elsif !opts[:only] && !opts[:except] 
    91             options.merge!(opts) 
     90          action = action.to_s 
     91          session_options.each do |opts| 
     92            next if opts[:if] && !opts[:if].call(request) 
     93            if opts[:only] && opts[:only].include?(action) 
     94              options.merge!(opts) 
     95            elsif opts[:except] && !opts[:except].include?(action) 
     96              options.merge!(opts) 
     97            elsif !opts[:only] && !opts[:except] 
     98              options.merge!(opts) 
     99            end 
     100          end 
     101           
     102          if options.empty? then options 
     103          else 
     104            options.delete :only 
     105            options.delete :except 
     106            options.delete :if 
     107            options[:disabled] ? false : options 
    92108          end 
    93109        end 
    94  
    95         options.delete :only 
    96         options.delete :except 
    97         options.delete :if 
    98  
    99         options[:disabled] ? false : options 
    100110      end 
    101111    end 
     
    109119    private 
    110120      def clear_persistant_model_associations #:doc: 
    111         session = @session.instance_variable_get("@data") 
    112         session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) } if session 
     121        if session = @session.instance_variable_get("@data") 
     122          session.each { |key, obj| obj.clear_association_cache if obj.respond_to?(:clear_association_cache) } 
     123        end 
    113124      end 
    114125  end