]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - classes/Profile.php
Update notice sorting for profile streams; extract more common code to Notice::addSin...
[quix0rs-gnu-social.git] / classes / Profile.php
index 332d51e2037ea92f542c42cb9d24c8beb6804ce1..62789a489946198b0275441f2f2eebe6ce3278c7 100644 (file)
@@ -252,58 +252,22 @@ class Profile extends Memcached_DataObject
     {
         $notice = new Notice();
 
-        // Temporary hack until notice_profile_id_idx is updated
-        // to (profile_id, id) instead of (profile_id, created, id).
-        // It's been falling back to PRIMARY instead, which is really
-        // very inefficient for a profile that hasn't posted in a few
-        // months. Even though forcing the index will cause a filesort,
-        // it's usually going to be better.
-        if (common_config('db', 'type') == 'mysql') {
-            $index = '';
-            $query =
-              "select id from notice force index (notice_profile_id_idx) ".
-              "where profile_id=" . $notice->escape($this->id);
-
-            if ($since_id != 0) {
-                $query .= " and id > $since_id";
-            }
-
-            if ($max_id != 0) {
-                $query .= " and id <= $max_id";
-            }
-
-            $query .= ' order by id DESC';
-
-            if (!is_null($offset)) {
-                $query .= " LIMIT $limit OFFSET $offset";
-            }
-
-            $notice->query($query);
-        } else {
-            $index = '';
-
-            $notice->profile_id = $this->id;
-
-            $notice->selectAdd();
-            $notice->selectAdd('id');
-
-            if ($since_id != 0) {
-                $notice->whereAdd('id > ' . $since_id);
-            }
+        $notice->profile_id = $this->id;
 
-            if ($max_id != 0) {
-                $notice->whereAdd('id <= ' . $max_id);
-            }
+        $notice->selectAdd();
+        $notice->selectAdd('id');
 
-            $notice->orderBy('id DESC');
+        Notice::addWhereSinceId($notice, $since_id);
+        Notice::addWhereMaxId($notice, $max_id);
 
-            if (!is_null($offset)) {
-                $notice->limit($offset, $limit);
-            }
+        $notice->orderBy('created DESC, id DESC');
 
-            $notice->find();
+        if (!is_null($offset)) {
+            $notice->limit($offset, $limit);
         }
 
+        $notice->find();
+
         $ids = array();
 
         while ($notice->fetch()) {