From d31397bd453f9003f9fdac465741dc61df2decd5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Tue, 28 Dec 2010 13:44:49 -0800 Subject: [PATCH] method to count notices linking to an URL --- classes/File.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/classes/File.php b/classes/File.php index 2b0e636c16..29a8f0f1c5 100644 --- a/classes/File.php +++ b/classes/File.php @@ -427,6 +427,7 @@ class File extends Memcached_DataObject if ($last) { self::blow('file:notice-ids:%s;last', $this->url); } + self::blow('file:notice-count:%d', $this->id); } /** @@ -489,4 +490,24 @@ class File extends Memcached_DataObject return $ids; } + + function noticeCount() + { + $cacheKey = sprintf('file:notice-count:%d', $this->id); + + $count = self::cacheGet($cacheKey); + + if ($count === false) { + + $f2p = new File_to_post(); + + $f2p->file_id = $this->id; + + $count = $f2p->count(); + + self::cacheSet($cacheKey, $count); + } + + return $count; + } } -- 2.39.5