diff options
author | Brion Vibber <brion@pobox.com> | 2010-12-17 16:31:19 -0800 |
---|---|---|
committer | Brion Vibber <brion@pobox.com> | 2010-12-17 16:31:19 -0800 |
commit | 3a831ff811daf2911fa4a14e1015d63e4451a2ab (patch) | |
tree | 37099ca5856eec80c10f2bb755827e63a40aa18e /classes/Profile.php | |
parent | 073f3e99cb5be798ab020eeedb28357b51f2e90f (diff) | |
parent | 5300d657cc881a1e8dba59498c90098930029d68 (diff) |
Merge branch 'sorting' into 0.9.x
Diffstat (limited to 'classes/Profile.php')
-rw-r--r-- | classes/Profile.php | 73 |
1 files changed, 20 insertions, 53 deletions
diff --git a/classes/Profile.php b/classes/Profile.php index 332d51e20..fe1a070bd 100644 --- a/classes/Profile.php +++ b/classes/Profile.php @@ -215,26 +215,29 @@ class Profile extends Memcached_DataObject function _streamTaggedDirect($tag, $offset, $limit, $since_id, $max_id) { // XXX It would be nice to do this without a join + // (necessary to do it efficiently on accounts with long history) $notice = new Notice(); $query = "select id from notice join notice_tag on id=notice_id where tag='". $notice->escape($tag) . - "' and profile_id=" . $notice->escape($this->id); + "' and profile_id=" . intval($this->id); - if ($since_id != 0) { - $query .= " and id > $since_id"; + $since = Notice::whereSinceId($since_id, 'id', 'notice.created'); + if ($since) { + $query .= " and ($since)"; } - if ($max_id != 0) { - $query .= " and id <= $max_id"; + $max = Notice::whereMaxId($max_id, 'id', 'notice.created'); + if ($max) { + $query .= " and ($max)"; } - $query .= ' order by id DESC'; + $query .= ' order by notice.created DESC, id DESC'; if (!is_null($offset)) { - $query .= " LIMIT $limit OFFSET $offset"; + $query .= " LIMIT " . intval($limit) . " OFFSET " . intval($offset); } $notice->query($query); @@ -252,58 +255,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()) { |