]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
cache groups per notice
authorEvan Prodromou <evan@status.net>
Thu, 7 Apr 2011 02:47:17 +0000 (22:47 -0400)
committerEvan Prodromou <evan@status.net>
Thu, 7 Apr 2011 02:47:17 +0000 (22:47 -0400)
classes/Notice.php

index a4f530c44facfe768ed9aec178a5a749d8249448..8098a8ace845c8cbf1d71011601ad19ab2ba59c0 100644 (file)
@@ -1250,27 +1250,39 @@ class Notice extends Memcached_DataObject
             return array();
         }
 
-        // XXX: cache me
+        $ids = array();
 
-        $groups = array();
+        $keypart = sprintf('notice:groups:%d', $this->id);
 
-        $gi = new Group_inbox();
+        $idstr = self::cacheGet($keypart);
 
-        $gi->selectAdd();
-        $gi->selectAdd('group_id');
+        if ($idstr !== false) {
+            $ids = explode(',', $idstr);
+        } else {
+            $gi = new Group_inbox();
 
-        $gi->notice_id = $this->id;
+            $gi->selectAdd();
+            $gi->selectAdd('group_id');
 
-        if ($gi->find()) {
-            while ($gi->fetch()) {
-                $group = User_group::staticGet('id', $gi->group_id);
-                if ($group) {
-                    $groups[] = $group;
+            $gi->notice_id = $this->id;
+
+            if ($gi->find()) {
+                while ($gi->fetch()) {
+                    $ids[] = $gi->group_id;
                 }
             }
+
+            self::cacheSet($keypart, implode(',', $ids));
         }
 
-        $gi->free();
+        $groups = array();
+
+        foreach ($ids as $id) {
+            $group = User_group::staticGet('id', $id);
+            if ($group) {
+                $groups[] = $group;
+            }
+        }
 
         return $groups;
     }