From 44c64816a5e90cc85769693e5f6bcb96934f57ef Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 6 Apr 2011 22:47:17 -0400 Subject: [PATCH] cache groups per notice --- classes/Notice.php | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index a4f530c44f..8098a8ace8 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -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; } -- 2.39.5