From: Brion Vibber Date: Fri, 17 Dec 2010 20:38:38 +0000 (-0800) Subject: Initial switch of public timeline stream to use timestamps for internal sorting X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=5de86f0ccc0208c2fc1a3924e4142bcac9679893;p=quix0rs-gnu-social.git Initial switch of public timeline stream to use timestamps for internal sorting --- diff --git a/classes/Notice.php b/classes/Notice.php index 079f56dcf9..b5a1b45971 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -654,7 +654,7 @@ class Notice extends Memcached_DataObject $notice->selectAdd(); // clears it $notice->selectAdd('id'); - $notice->orderBy('id DESC'); + $notice->orderBy('created DESC, id DESC'); if (!is_null($offset)) { $notice->limit($offset, $limit); @@ -668,12 +668,14 @@ class Notice extends Memcached_DataObject $notice->whereAdd('is_local !='. Notice::GATEWAY); } - if ($since_id != 0) { - $notice->whereAdd('id > ' . $since_id); + $since = Notice::getAsTimestamp($since_id); + if ($since) { + $notice->whereAdd(sprintf("(created = '%s' and id > %d) or (created > '%s')", $since, $since_id, $since)); } - if ($max_id != 0) { - $notice->whereAdd('id <= ' . $max_id); + $max = Notice::getAsTimestamp($max_id); + if ($max) { + $notice->whereAdd(sprintf("(created < '%s') or (created = '%s' and id <= %d)", $max, $max, $max_id)); } $ids = array(); @@ -1988,16 +1990,20 @@ class Notice extends Memcached_DataObject */ public static function getAsTimestamp($id) { + if (!$id) { + return false; + } + $notice = Notice::staticGet('id', $id); if ($notice) { return $notice->created; - } else { - $deleted = Deleted_notice::staticGet('id', $id); - if ($deleted) { - return $deleted->created; - } else { - return false; - } } + + $deleted = Deleted_notice::staticGet('id', $id); + if ($deleted) { + return $deleted->created; + } + + return false; } }