summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorZach Copley <zach@status.net>2010-09-27 15:01:03 -0700
committerZach Copley <zach@status.net>2010-09-29 16:35:12 -0700
commitc19e592fa80f616a18718c4650ea0ffc9661f7ce (patch)
tree5134fc868613dbd29acb769e49a0dd1b3de74a30 /classes
parentd2ef0cf233e7e3f4567aff6ff7c94e666da5ee95 (diff)
Move hasFave() to Profile
Diffstat (limited to 'classes')
-rw-r--r--classes/Profile.php35
-rw-r--r--classes/User.php33
2 files changed, 37 insertions, 31 deletions
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();
diff --git a/classes/User.php b/classes/User.php
index b85192b29..27299e62e 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -412,37 +412,8 @@ class User extends Memcached_DataObject
function hasFave($notice)
{
- $cache = common_memcache();
-
- // XXX: Kind of a hack.
-
- if ($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);
+ $profile = $this->getProfile();
+ return $profile->hasFave($notice);
}
function mutuallySubscribed($other)