]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
cache getReplies() values
authorEvan Prodromou <evan@status.net>
Thu, 7 Apr 2011 03:46:51 +0000 (23:46 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 7 Apr 2011 03:46:51 +0000 (23:46 -0400)
classes/Notice.php

index b948e9de733af6708183ab223d49196c25482d40..6ca4c711fd21b632d620ca5d56ccb223b2ba1d6e 100644 (file)
@@ -1208,23 +1208,28 @@ class Notice extends Memcached_DataObject
      */
     function getReplies()
     {
-        // XXX: cache me
+        $keypart = sprintf('notice:reply_ids:%d', $this->id);
 
-        $ids = array();
+        $idstr = self::cacheGet($keypart);
 
-        $reply = new Reply();
-        $reply->selectAdd();
-        $reply->selectAdd('profile_id');
-        $reply->notice_id = $this->id;
+        if ($idstr !== false) {
+            $ids = explode(',', $idstr);
+        } else {
+            $ids = array();
 
-        if ($reply->find()) {
-            while($reply->fetch()) {
-                $ids[] = $reply->profile_id;
+            $reply = new Reply();
+            $reply->selectAdd();
+            $reply->selectAdd('profile_id');
+            $reply->notice_id = $this->id;
+
+            if ($reply->find()) {
+                while($reply->fetch()) {
+                    $ids[] = $reply->profile_id;
+                }
             }
+            self::cacheSet($keypart, implode(',', $ids));
         }
 
-        $reply->free();
-
         return $ids;
     }