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 From 3960c9ad39d96cdfef390065f15f9f0fc280f37c Mon Sep 17 00:00:00 2001 From: Zach Copley Date: Tue, 28 Sep 2010 15:46:14 -0700 Subject: Move blowFavesCache() to Profile --- classes/Profile.php | 14 ++++++++++++++ classes/User.php | 11 +---------- 2 files changed, 15 insertions(+), 10 deletions(-) (limited to 'classes/Profile.php') diff --git a/classes/Profile.php b/classes/Profile.php index 668f25d2e..3844077e6 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -551,6 +551,20 @@ class Profile extends Memcached_DataObject return $cnt; } + function blowFavesCache() + { + $cache = common_memcache(); + if ($cache) { + // Faves don't happen chronologically, so we need to blow + // ;last cache, too + $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id)); + $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last')); + $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id)); + $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last')); + } + $this->blowFaveCount(); + } + function blowSubscriberCount() { $c = common_memcache(); diff --git a/classes/User.php b/classes/User.php index 27299e62e..e784fd9e9 100644 --- a/classes/User.php +++ b/classes/User.php @@ -482,17 +482,8 @@ class User extends Memcached_DataObject function blowFavesCache() { - $cache = common_memcache(); - if ($cache) { - // Faves don't happen chronologically, so we need to blow - // ;last cache, too - $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id)); - $cache->delete(common_cache_key('fave:ids_by_user:'.$this->id.';last')); - $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id)); - $cache->delete(common_cache_key('fave:ids_by_user_own:'.$this->id.';last')); - } $profile = $this->getProfile(); - $profile->blowFaveCount(); + $profile->blowFavesCache(); } function getSelfTags() -- cgit v1.2.3-54-g00ecf