compress window-getting to one function
darcs-hash:20080915071835-84dde-173e6afde44c3348c3314c638e2a67dfb333c011.gz
This commit is contained in:
parent
d86f954797
commit
7334add156
@ -146,10 +146,7 @@ class User extends DB_DataObject
|
|||||||
|
|
||||||
if (common_config('memcached', 'enabled')) {
|
if (common_config('memcached', 'enabled')) {
|
||||||
if ($offset + $limit < WITHFRIENDS_CACHE_WINDOW) {
|
if ($offset + $limit < WITHFRIENDS_CACHE_WINDOW) {
|
||||||
$cached = $this->noticesWithFriendsCachedWindow();
|
$cached = $this->noticesWithFriendsWindow();
|
||||||
if (!$cached) {
|
|
||||||
$cached = $this->noticesWithFriendsWindow();
|
|
||||||
}
|
|
||||||
$wrapper = new NoticeWrapper(array_slice($cached, $offset, $limit));
|
$wrapper = new NoticeWrapper(array_slice($cached, $offset, $limit));
|
||||||
return $wrapper;
|
return $wrapper;
|
||||||
}
|
}
|
||||||
@ -166,16 +163,6 @@ class User extends DB_DataObject
|
|||||||
return $notice;
|
return $notice;
|
||||||
}
|
}
|
||||||
|
|
||||||
function noticesWithFriendsCachedWindow() {
|
|
||||||
$cache = new Memcache();
|
|
||||||
$res = $cache->connect(common_config('memcached', 'server'), common_config('memcached', 'port'));
|
|
||||||
if (!$res) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
$notices = $cache->get(common_cache_key('user:notices_with_friends:' . $this->id));
|
|
||||||
return $notices;
|
|
||||||
}
|
|
||||||
|
|
||||||
function noticesWithFriendsWindow() {
|
function noticesWithFriendsWindow() {
|
||||||
|
|
||||||
$cache = new Memcache();
|
$cache = new Memcache();
|
||||||
@ -185,6 +172,12 @@ class User extends DB_DataObject
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$notices = $cache->get(common_cache_key('user:notices_with_friends:' . $this->id));
|
||||||
|
|
||||||
|
if ($notices) {
|
||||||
|
return $notices;
|
||||||
|
}
|
||||||
|
|
||||||
$notice = new Notice();
|
$notice = new Notice();
|
||||||
|
|
||||||
$notice->query('SELECT notice.* ' .
|
$notice->query('SELECT notice.* ' .
|
||||||
|
Loading…
Reference in New Issue
Block a user