summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@prodromou.name>2008-11-22 11:33:47 -0500
committerEvan Prodromou <evan@prodromou.name>2008-11-22 11:33:47 -0500
commit5632b2e6d5b54bcafc06b9979523ecc9b69ec1c4 (patch)
tree09781e1a6ef0854c39000c80bf4e50a4ba258627 /classes
parent64101cc57935725d3d28186e5043e656ead93ec6 (diff)
use cached fave stream to save DB hits for faves
darcs-hash:20081122163347-84dde-abb0dfc800f65f50951c5517af3bfda48013c6ed.gz
Diffstat (limited to 'classes')
-rw-r--r--classes/User.php22
1 files changed, 22 insertions, 0 deletions
diff --git a/classes/User.php b/classes/User.php
index 38a56d1c8..12f174944 100644
--- a/classes/User.php
+++ b/classes/User.php
@@ -273,6 +273,28 @@ 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.
+ $faves = $this->favoriteNotices(0, NOTICE_CACHE_WINDOW);
+
+ while ($faves->fetch()) {
+ if ($faves->id > $notice->id) {
+ # If we passed it, it's not a fave
+ return false;
+ } else if ($faves->id == $notice->id) {
+ # If it matches a cached notice, then it's a fave
+ return true;
+ }
+ }
+ # If it's past the end of the cache window,
+ # fall through to the default
+ }
+
$fave = Fave::pkeyGet(array('user_id' => $this->id,
'notice_id' => $notice->id));
return ((is_null($fave)) ? false : true);