From 8564fc51c53de7a0670720eec437000a6b972688 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Mon, 6 Dec 2010 16:38:02 -0500 Subject: [PATCH] cache generated activity info --- classes/Notice.php | 10 +++++++++- lib/activity.php | 14 +++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/classes/Notice.php b/classes/Notice.php index de5104fdbb..46e1dca35e 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1236,10 +1236,16 @@ class Notice extends Memcached_DataObject function asActivity($cur = null, $source = false) { + $act = self::cacheGet('notice:as-activity:'.$this->id); + + if (!empty($act)) { + return $act; + } + $act = new Activity(); if (Event::handle('StartNoticeAsActivity', array($this, &$act))) { - + $profile = $this->getProfile(); $act->actor = ActivityObject::fromProfile($profile); @@ -1400,6 +1406,8 @@ class Notice extends Memcached_DataObject Event::handle('EndNoticeAsActivity', array($this, &$act)); } + self::cacheSet('notice:as-activity:'.$this->id, $act); + return $act; } diff --git a/lib/activity.php b/lib/activity.php index e29bc1a25d..712800817c 100644 --- a/lib/activity.php +++ b/lib/activity.php @@ -329,6 +329,14 @@ class Activity function asString($namespace=false, $author=true) { + $c = Cache::instance(); + + $str = $c->get('activity:as-string:'.Cache::keyize($this->id)); + + if (!empty($str)) { + return $str; + } + $xs = new XMLStringer(true); if ($namespace) { @@ -549,7 +557,11 @@ class Activity $xs->elementEnd('entry'); - return $xs->getString(); + $str = $xs->getString(); + + $c->set('activity:as-string:'.Cache::keyize($this->id), $str); + + return $str; } private function _child($element, $tag, $namespace=self::SPEC)