- Timestamp:
- 10/01/08 04:26:27 (2 months ago)
- Location:
- events/phpframework/sabel/trunk
- Files:
-
- 5 modified
-
app/aspects/Transaction.php (modified) (1 diff)
-
app/aspects/UserCache.php (modified) (4 diffs)
-
app/views/Submenu.php (modified) (1 diff)
-
config/environment.php (modified) (1 diff)
-
lib/UserCache.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
events/phpframework/sabel/trunk/app/aspects/Transaction.php
r20329 r20334 8 8 9 9 try { 10 l("before: transaction");11 10 $result = $inv->proceed(); 12 l("after: transaction");13 11 Sabel_Db_Transaction::commit(); 14 12 return $result; -
events/phpframework/sabel/trunk/app/aspects/UserCache.php
r20329 r20334 27 27 28 28 $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); 35 35 } 36 36 } … … 41 41 42 42 $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); 49 49 } 50 50 } … … 55 55 56 56 $cache = UserCache::getInstance(); 57 list ($fp, $data) = $cache->lock($userId); 57 58 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); 63 62 } 64 63 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); 70 69 } 71 70 } … … 76 75 77 76 $cache = UserCache::getInstance(); 77 list ($fp, $data) = $cache->lock($userId); 78 78 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); 84 82 } 85 83 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); 91 89 } 92 90 } -
events/phpframework/sabel/trunk/app/views/Submenu.php
r20329 r20334 95 95 96 96 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); 101 100 } 102 101 -
events/phpframework/sabel/trunk/config/environment.php
r20329 r20334 4 4 * define sabel environment. 5 5 */ 6 if (!defined("ENVIRONMENT")) define("ENVIRONMENT", PRODUCTION);6 // if (!defined("ENVIRONMENT")) define("ENVIRONMENT", PRODUCTION); 7 7 // if (!defined("ENVIRONMENT")) define("ENVIRONMENT", BENCHMARK); 8 8 // if (!defined("ENVIRONMENT")) define("ENVIRONMENT", TEST); -
events/phpframework/sabel/trunk/lib/UserCache.php
r20329 r20334 29 29 { 30 30 $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; 42 32 } 43 33 44 34 public function lock($userId, $mode = "ab+") 45 35 { 46 $i = 0;47 36 $path = $this->getPath($userId); 37 $fp = fopen($path, $mode); 38 $data = $this->_read($path); 48 39 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; 57 53 } 58 59 return false;60 54 } 61 55
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)