From c19e592fa80f616a18718c4650ea0ffc9661f7ce Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Mon, 27 Sep 2010 15:01:03 -0700 Subject: Move hasFave() to Profile --- classes/Profile.php | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'classes/Profile.php') diff --git a/classes/Profile.php b/classes/Profile.php index 3a381fcc8..668f25d2e 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -473,6 +473,41 @@ class Profile extends Memcached_DataObject return $cnt; } + function hasFave($notice) + { + $cache = common_memcache(); + + // XXX: Kind of a hack. + + if (!empty($cache)) { + // This is the stream of favorite notices, in rev chron + // order. This forces it into cache. + + $ids = Fave::stream($this->id, 0, NOTICE_CACHE_WINDOW); + + // If it's in the list, then it's a fave + + if (in_array($notice->id, $ids)) { + return true; + } + + // If we're not past the end of the cache window, + // then the cache has all available faves, so this one + // is not a fave. + + if (count($ids) < NOTICE_CACHE_WINDOW) { + return false; + } + + // Otherwise, cache doesn't have all faves; + // fall through to the default + } + + $fave = Fave::pkeyGet(array('user_id' => $this->id, + 'notice_id' => $notice->id)); + return ((is_null($fave)) ? false : true); + } + function faveCount() { $c = common_memcache(); -- cgit v1.2.3-54-g00ecf