Changeset 279

Show
Ignore:
Timestamp:
06/11/07 13:01:17 (1 year ago)
Author:
e.@brainspl.at
Message:

a few session optimization, thanks for pushing me ara. session key generation used to be an orser of magnitude slower, now its fast. a few touchups elsewhere

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/README

    r278 r279  
    4242Note the <tt>r.resource :posts</tt> macro. That makes it possible to use a RESTful CRUD style controller for the posts resource 
    4343 
    44         Merb::RouteMatcher.prepare do |r| 
     44        Merb::Router.prepare do |r| 
    4545          r.resources :posts 
    4646          r.default_routes 
     
    153153            respond_to {|format| 
    154154              format.html { render } 
    155               format.js   { render :js => 'index'
     155              format.js   { render :js => :index
    156156              format.xml  { render :xml => @posts.to_xml } 
    157157            } 
  • trunk/Rakefile

    r263 r279  
    6262  s.add_dependency('mime-types') 
    6363  s.add_dependency('xml-simple') 
    64   s.add_dependency('archive-tar-minitar')  
    6564  s.required_ruby_version = '>= 1.8.4' 
    6665 
  • trunk/lib/merb/merb_controller.rb

    r263 r279  
    3636      if MULTIPART_REGEXP =~ @env[Mongrel::Const::UPCASE_CONTENT_TYPE] && @method == :post 
    3737        querystring.update(parse_multipart(request, $1)) 
    38       elsif @method == :post 
     38      elsif @method == :post || @method == :put 
    3939        if [Mongrel::Const::APPLICATION_JSON, Mongrel::Const::TEXT_JSON].include?(@env[Mongrel::Const::UPCASE_CONTENT_TYPE]) 
    4040          MERB_LOGGER.info("JSON Request") 
  • trunk/lib/merb/merb_handler.rb

    r216 r279  
    1111 
    1212 
    13  
     13require 'unroller' 
    1414class MerbHandler < Mongrel::HttpHandler 
    1515  @@file_only_methods = ["GET","HEAD"] 
     
    6666        controller = nil 
    6767        controller, action = Merb::Dispatcher.handle(request, response) 
    68          
    6968        MERB_LOGGER.info("Routing to controller: #{controller.class} action: #{action}\nRoute Recognition & Parsing HTTP Input took: #{Time.now - start} seconds") 
    7069      rescue Object => e 
  • trunk/lib/merb/merb_view_context.rb

    r274 r279  
    5252      @controller 
    5353    end 
     54     
     55    def request 
     56       @controller.request   
     57    end 
     58             
     59    def params 
     60      @controller.params 
     61    end   
     62     
     63    def cookies 
     64      @controller.cookies 
     65    end   
     66 
     67    def headers 
     68      @controller.headers 
     69    end 
     70     
     71    def session 
     72      @controller.session 
     73    end 
     74 
     75    def response 
     76      @controller.response 
     77    end 
    5478       
    5579    alias_method :old_respond_to?, :respond_to? 
  • trunk/lib/merb/mixins/controller_mixin.rb

    r241 r279  
    229229    end   
    230230     
    231     def rand_uuid 
    232       "%04x%04x-%04x-%04x-%04x-%06x%06x" % [ 
    233                                             rand(0x0010000), 
    234                                             rand(0x0010000), 
    235                                             rand(0x0010000), 
    236                                             rand(0x0010000), 
    237                                             rand(0x0010000), 
    238                                             rand(0x1000000), 
    239                                             rand(0x1000000), 
    240                                            ] 
    241     end 
    242231 
    243232    def escape_xml(obj) 
  • trunk/lib/merb/session/merb_ar_session.rb

    r224 r279  
    99      before = @cookies[_session_id_key] 
    1010      @session, @cookies[_session_id_key] = Merb::Session.persist(@cookies[_session_id_key]) 
    11       @_fingerprint_before = Marshal.dump(@session).hash 
     11      @session.dirty = false 
    1212      @_new_cookie = @cookies[_session_id_key] != before 
    1313    end 
     
    1515    def finalize_session 
    1616      MERB_LOGGER.info("Finalize session") 
    17       unless Marshal.dump(@session).hash == @_fingerprint_before 
    18         @session.save 
    19       end 
     17      @session.save if @session.dirty 
    2018      set_cookie(_session_id_key, @cookies[_session_id_key], Time.now+Merb::Const::WEEK*2) if @_new_cookie 
    2119    end  
     
    2927    before_save :marshal_data! 
    3028    before_save :raise_on_session_data_overflow! 
    31    
     29    attr_accessor :dirty 
    3230    RAND_CHARS = [*'A'..'Z'] + [*'0'..'9'] + [*'a'..'z'] 
    3331   
     
    3533      # Generates a new session ID and creates a row for the new session in the database. 
    3634      def generate 
    37         rand_max = RAND_CHARS.size 
    38         sid = (0...32).inject("") { |ret,_| ret << RAND_CHARS[rand(rand_max)] } 
     35        sid = "%04x%04x-%04x-%04x-%04x-%06x%06x" % [ 
     36                                              rand(0x0010000), 
     37                                              rand(0x0010000), 
     38                                              rand(0x0010000), 
     39                                              rand(0x0010000), 
     40                                              rand(0x0010000), 
     41                                              rand(0x1000000), 
     42                                              rand(0x1000000), 
     43                                             ] 
    3944        create(:session_id => sid, :data => {}) 
    4045      end 
     
    8489     
    8590    def []=(key, val) 
     91      @dirty = true 
    8692      data[key] = val   
    8793    end 
  • trunk/tools/allison/cache/BODY

    r263 r279  
    1 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>%title%</title><link type="text/css" rel="stylesheet" media="screen" href="%style_url%"/><script type="text/javascript"> 
     1<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>%title%</title><link type="text/css" media="screen" href="%style_url%" rel="stylesheet"/><script type="text/javascript"> 
    22// Javascript for Allison RDoc template 
    33// Copyright 2006 Cloudburst LLC 
  • trunk/tools/allison/cache/INDEX

    r263 r279  
    1 <html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>%title%</title><link type="text/css" rel="stylesheet" media="screen" href="rdoc-style.css"/><meta content="0;url=%initial_page%" http-equiv="refresh"/></head><body><div id="container"><div class="curve" id="preheader_curve_0"></div><div class="curve" id="preheader_curve_1"></div><div class="curve" id="preheader_curve_2"></div><div class="curve" id="preheader_curve_3"></div><div class="curve" id="preheader_curve_4"></div><div class="curve" id="preheader_curve_5"></div><div class="curve" id="preheader_curve_6"></div><div class="curve" id="preheader_curve_7"></div><div class="curve" id="preheader_curve_8"></div><div class="curve" id="preheader_curve_9"></div><div id="header"><span id="title"><p>&nbsp;</p><h1>Ruby Documentation</h1></span></div><div class="clear"></div><div id="redirect"><a href="%initial_page%"><h1>Redirect</h1></a></div></div></body></html> 
     1<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><head><meta content="text/html; charset=utf-8" http-equiv="Content-Type"/><title>%title%</title><link type="text/css" media="screen" href="rdoc-style.css" rel="stylesheet"/><meta content="0;url=%initial_page%" http-equiv="refresh"/></head><body><div id="container"><div class="curve" id="preheader_curve_0"></div><div class="curve" id="preheader_curve_1"></div><div class="curve" id="preheader_curve_2"></div><div class="curve" id="preheader_curve_3"></div><div class="curve" id="preheader_curve_4"></div><div class="curve" id="preheader_curve_5"></div><div class="curve" id="preheader_curve_6"></div><div class="curve" id="preheader_curve_7"></div><div class="curve" id="preheader_curve_8"></div><div class="curve" id="preheader_curve_9"></div><div id="header"><span id="title"><p>&nbsp;</p><h1>Ruby Documentation</h1></span></div><div class="clear"></div><div id="redirect"><a href="%initial_page%"><h1>Redirect</h1></a></div></div></body></html>