summaryrefslogtreecommitdiff
path: root/classes/User.php
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-09-15 03:18:35 -0400
committerEvan Prodromou <evan@prodromou.name>2008-09-15 03:18:35 -0400
commit7334add15620b1cd2ee1d6df4bb8eb55c08657fd (patch)
treea036faf08987da5ec5607e5a88f7065ae92a4e81 /classes/User.php
parentd86f95479726d128883a67a14d5924460ec09e4b (diff)
compress window-getting to one function
darcs-hash:20080915071835-84dde-173e6afde44c3348c3314c638e2a67dfb333c011.gz
Diffstat (limited to 'classes/User.php')
-rw-r--r--classes/User.php21
1 files changed, 7 insertions, 14 deletions
diff --git a/classes/User.php b/classes/User.php
index 8b73923a7..65b2d663e 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -146,10 +146,7 @@ class User extends DB_DataObject
if (common_config('memcached', 'enabled')) {
if ($offset + $limit < WITHFRIENDS_CACHE_WINDOW) {
- $cached = $this->noticesWithFriendsCachedWindow();
- if (!$cached) {
- $cached = $this->noticesWithFriendsWindow();
- }
+ $cached = $this->noticesWithFriendsWindow();
$wrapper = new NoticeWrapper(array_slice($cached, $offset, $limit));
return $wrapper;
}
@@ -166,16 +163,6 @@ class User extends DB_DataObject
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() {
$cache = new Memcache();
@@ -185,6 +172,12 @@ class User extends DB_DataObject
return NULL;
}
+ $notices = $cache->get(common_cache_key('user:notices_with_friends:' . $this->id));
+
+ if ($notices) {
+ return $notices;
+ }
+
$notice = new Notice();
$notice->query('SELECT notice.* ' .