]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
make profile notice getting use ids
authorEvan Prodromou <evan@controlyourself.ca>
Fri, 1 May 2009 18:27:57 +0000 (11:27 -0700)
committerEvan Prodromou <evan@controlyourself.ca>
Fri, 1 May 2009 18:27:57 +0000 (11:27 -0700)
classes/Notice.php
classes/Profile.php

index 808631f4dcb48491c85a4320de34b7e3b44c65b5..eceed325b09872bcdfac1a244462aca862788073 100644 (file)
@@ -363,10 +363,10 @@ class Notice extends Memcached_DataObject
     {
         if ($this->is_local) {
             $cache = common_memcache();
-            if ($cache) {
-                $cache->delete(common_cache_key('profile:notices:'.$this->profile_id));
+            if (!empty($cache)) {
+                $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id));
                 if ($blowLast) {
-                    $cache->delete(common_cache_key('profile:notices:'.$this->profile_id.';last'));
+                    $cache->delete(common_cache_key('profile:notice_ids:'.$this->profile_id.';last'));
                 }
             }
         }
index f3bfe299cfb8d474dfae3ad57e29f2b8517f29cd..ae5641d79d69bb2a03d2faa6b1a3b9e43d992cc3 100644 (file)
@@ -155,14 +155,51 @@ class Profile extends Memcached_DataObject
 
     function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0)
     {
-        $qry =
-          'SELECT * ' .
-          'FROM notice ' .
-          'WHERE profile_id = %d ';
-
-        return Notice::getStream(sprintf($qry, $this->id),
-                                 'profile:notices:'.$this->id,
-                                 $offset, $limit, $since_id, $before_id);
+        // XXX: I'm not sure this is going to be any faster. It probably isn't.
+        $ids = Notice::stream(array($this, '_streamDirect'),
+                              array(),
+                              'profile:notice_ids:' . $this->id,
+                              $offset, $limit, $since_id, $before_id);
+
+        return Notice::getStreamByIds($ids);
+    }
+
+    function _streamDirect($offset, $limit, $since_id, $before_id, $since)
+    {
+        $notice = new Notice();
+
+        $notice->profile_id = $this->id;
+
+        $notice->selectAdd();
+        $notice->selectAdd('id');
+
+        if ($since_id != 0) {
+            $notice->whereAdd('id > ' . $since_id);
+        }
+
+        if ($before_id != 0) {
+            $notice->whereAdd('id < ' . $before_id);
+        }
+
+        if (!is_null($since)) {
+            $notice->whereAdd('created > \'' . date('Y-m-d H:i:s', $since) . '\'');
+        }
+
+        $notice->orderBy('id DESC');
+
+        if (!is_null($offset)) {
+            $notice->limit($offset, $limit);
+        }
+
+        $ids = array();
+
+        if ($notice->find()) {
+            while ($notice->fetch()) {
+                $ids[] = $notice->id;
+            }
+        }
+
+        return $ids;
     }
 
     function isMember($group)