]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
compress window-getting to one function
authorEvan Prodromou <evan@prodromou.name>
Mon, 15 Sep 2008 07:18:35 +0000 (03:18 -0400)
committerEvan Prodromou <evan@prodromou.name>
Mon, 15 Sep 2008 07:18:35 +0000 (03:18 -0400)
darcs-hash:20080915071835-84dde-173e6afde44c3348c3314c638e2a67dfb333c011.gz

classes/User.php

index 8b73923a775ea57e293ead993b7d7be0f3d3bf47..65b2d663ecb0b81cfcc9cf87ef496f66d161fa16 100644 (file)
@@ -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.* ' .