]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
use cached fave stream to save DB hits for faves
authorEvan Prodromou <evan@prodromou.name>
Sat, 22 Nov 2008 16:33:47 +0000 (11:33 -0500)
committerEvan Prodromou <evan@prodromou.name>
Sat, 22 Nov 2008 16:33:47 +0000 (11:33 -0500)
darcs-hash:20081122163347-84dde-abb0dfc800f65f50951c5517af3bfda48013c6ed.gz

classes/User.php

index 38a56d1c818af94c50464f5bc287da8d74b371bf..12f17494434b9529f91fe9eba3cd2092d8481d53 100644 (file)
@@ -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);