Changeset 5247 in subversion


Ignore:
Timestamp:
Sep 20, 2011 3:34:48 AM (20 months ago)
Author:
alec
Message:
  • Improve performance by skipping redundant SELECT query when writing new session into DB
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/roundcubemail/program/include/rcube_session.php

    r5226 r5247  
    5353  public function __construct($db, $config) 
    5454  { 
    55     $this->db = $db; 
    56     $this->start = microtime(true); 
    57     $this->ip = $_SERVER['REMOTE_ADDR']; 
     55    $this->db      = $db; 
     56    $this->start   = microtime(true); 
     57    $this->ip      = $_SERVER['REMOTE_ADDR']; 
    5858    $this->logging = $config->get('log_session', false); 
    5959 
     
    127127  { 
    128128    $sql_result = $this->db->query( 
    129       "SELECT vars, ip, changed FROM ".get_table_name('session')." WHERE sess_id = ?", 
    130       $key); 
    131  
    132     if ($sql_arr = $this->db->fetch_assoc($sql_result)) { 
     129      "SELECT vars, ip, changed FROM ".get_table_name('session') 
     130      ." WHERE sess_id = ?", $key); 
     131 
     132    if ($sql_result && ($sql_arr = $this->db->fetch_assoc($sql_result))) { 
    133133      $this->changed = strtotime($sql_arr['changed']); 
    134134      $this->ip      = $sql_arr['ip']; 
     
    157157    $now = $this->db->fromunixtime((int)$ts); 
    158158 
     159    // no session row in DB (db_read() returns false) 
     160    if (!$this->key) { 
     161      $oldvars = false; 
     162    } 
    159163    // use internal data from read() for fast requests (up to 0.5 sec.) 
    160     if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) { 
     164    else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) { 
    161165      $oldvars = $this->vars; 
    162     } else { // else read data again from DB 
     166    } 
     167    else { // else read data again from DB 
    163168      $oldvars = $this->db_read($key); 
    164169    } 
     
    281286    $ts = microtime(true); 
    282287 
     288    // no session data in cache (mc_read() returns false) 
     289    if (!$this->key) 
     290      $oldvars = false; 
    283291    // use internal data for fast requests (up to 0.5 sec.) 
    284     if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) 
     292    else if ($key == $this->key && (!$this->vars || $ts - $this->start < 0.5)) 
    285293      $oldvars = $this->vars; 
    286294    else // else read data again 
Note: See TracChangeset for help on using the changeset viewer.