Changeset 20334 for events

Show
Ignore:
Timestamp:
10/01/08 04:26:27 (2 months ago)
Author:
sabel
Message:

clean-up

Location:
events/phpframework/sabel/trunk
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • events/phpframework/sabel/trunk/app/aspects/Transaction.php

    r20329 r20334  
    88     
    99    try { 
    10       l("before: transaction"); 
    1110      $result = $inv->proceed(); 
    12       l("after: transaction"); 
    1311      Sabel_Db_Transaction::commit(); 
    1412      return $result; 
  • events/phpframework/sabel/trunk/app/aspects/UserCache.php

    r20329 r20334  
    2727     
    2828    $cache = UserCache::getInstance(); 
    29     if ($data = $cache->read($userId)) { 
    30       if ($fp = $cache->lock($userId)) { 
    31         $data["statuses"]++; 
    32         $data["comment"] = $comment; 
    33         $cache->write($fp, $data); 
    34       } 
     29    list ($fp, $data) = $cache->lock($userId); 
     30     
     31    if ($data) { 
     32      $data["statuses"]++; 
     33      $data["comment"] = $comment; 
     34      $cache->write($fp, $data); 
    3535    } 
    3636  } 
     
    4141     
    4242    $cache = UserCache::getInstance(); 
    43     if ($data = $cache->read($userId)) { 
    44       if ($fp = $cache->lock($userId)) { 
    45         $data["statuses"]--; 
    46         $data["comment"] = Status::getLatestCommentByUserId($userId); 
    47         $cache->write($fp, $data); 
    48       } 
     43    list ($fp, $data) = $cache->lock($userId); 
     44     
     45    if ($data) { 
     46      $data["statuses"]--; 
     47      $data["comment"] = Status::getLatestCommentByUserId($userId); 
     48      $cache->write($fp, $data); 
    4949    } 
    5050  } 
     
    5555     
    5656    $cache = UserCache::getInstance(); 
     57    list ($fp, $data) = $cache->lock($userId); 
    5758     
    58     if ($data = $cache->read($userId)) { 
    59       if ($fp = $cache->lock($userId)) { 
    60         $data["friends"]++; 
    61         $cache->write($fp, $data); 
    62       } 
     59    if ($data) { 
     60      $data["friends"]++; 
     61      $cache->write($fp, $data); 
    6362    } 
    6463     
    65     if ($data = $cache->read($targetId)) { 
    66       if ($fp = $cache->lock($targetId)) { 
    67         $data["followers"]++; 
    68         $cache->write($fp, $data); 
    69       } 
     64    list ($fp, $data) = $cache->lock($targetId); 
     65     
     66    if ($data) { 
     67      $data["followers"]++; 
     68      $cache->write($fp, $data); 
    7069    } 
    7170  } 
     
    7675     
    7776    $cache = UserCache::getInstance(); 
     77    list ($fp, $data) = $cache->lock($userId); 
    7878     
    79     if ($data = $cache->read($userId)) { 
    80       if ($fp = $cache->lock($userId)) { 
    81         $data["friends"]--; 
    82         $cache->write($fp, $data); 
    83       } 
     79    if ($data) { 
     80      $data["friends"]--; 
     81      $cache->write($fp, $data); 
    8482    } 
    8583     
    86     if ($data = $cache->read($targetId)) { 
    87       if ($fp = $cache->lock($targetId)) { 
    88         $data["followers"]--; 
    89         $cache->write($fp, $data); 
    90       } 
     84    list ($fp, $data) = $cache->lock($targetId); 
     85     
     86    if ($data) { 
     87      $data["followers"]--; 
     88      $cache->write($fp, $data); 
    9189    } 
    9290  } 
  • events/phpframework/sabel/trunk/app/views/Submenu.php

    r20329 r20334  
    9595     
    9696    if ((ENVIRONMENT & PRODUCTION) > 0 && !$data) { 
    97       if ($fp = $cache->lock($userId)) { 
    98         $data = $this->_getUserData($userId); 
    99         $cache->write($fp, $data); 
    100       } 
     97      list ($fp) = $cache->lock($userId); 
     98      $data = $this->_getUserData($userId); 
     99      $cache->write($fp, $data); 
    101100    } 
    102101     
  • events/phpframework/sabel/trunk/config/environment.php

    r20329 r20334  
    44 * define sabel environment. 
    55 */ 
    6 if (!defined("ENVIRONMENT")) define("ENVIRONMENT", PRODUCTION); 
     6// if (!defined("ENVIRONMENT")) define("ENVIRONMENT", PRODUCTION); 
    77// if (!defined("ENVIRONMENT")) define("ENVIRONMENT", BENCHMARK); 
    88// if (!defined("ENVIRONMENT")) define("ENVIRONMENT", TEST); 
  • events/phpframework/sabel/trunk/lib/UserCache.php

    r20329 r20334  
    2929  { 
    3030    $path = $this->getPath($userId); 
    31     if (is_file($path)) { 
    32       include ($path); 
    33       if ($this->check($data)) { 
    34         return $data; 
    35       } else { 
    36         unlink($path); 
    37         return false; 
    38       } 
    39     } else { 
    40       return false; 
    41     } 
     31    return (is_file($path)) ? $this->_read($path) : false; 
    4232  } 
    4333   
    4434  public function lock($userId, $mode = "ab+") 
    4535  { 
    46     $i = 0; 
    4736    $path = $this->getPath($userId); 
     37    $fp   = fopen($path, $mode); 
     38    $data = $this->_read($path); 
    4839     
    49     while (++$i < 5) { 
    50       $fp = fopen($path, $mode); 
    51       if (flock($fp, LOCK_EX)) { 
    52         ftruncate($fp, 0); 
    53         return $fp; 
    54       } else { 
    55         usleep(mt_rand(50000, 500000)); 
    56       } 
     40    flock($fp, LOCK_EX); 
     41    ftruncate($fp, 0); 
     42     
     43    return array($fp, $data); 
     44  } 
     45   
     46  protected function _read($path) 
     47  { 
     48    include ($path); 
     49    if (isset($data) && $this->check($data)) { 
     50      return $data; 
     51    } else { 
     52      return false; 
    5753    } 
    58      
    59     return false; 
    6054  } 
    6155