Avoid ordering just by a timestamp

Try to also employ an id when possible.
Involves reworking some of the indices.
This commit is contained in:
Alexei Sorokin
2020-09-15 16:59:27 +03:00
committed by Diogo Peralta Cordeiro
parent ae4f3176b1
commit a0f72fe5c6
41 changed files with 633 additions and 656 deletions

View File

@@ -21,30 +21,28 @@ class RawEventsNoticeStream extends NoticeStream
public function getNoticeIds($offset, $limit, $since_id, $max_id)
{
$notice = new Notice();
$qry = null;
$qry = 'SELECT notice.* FROM notice ';
$qry .= 'INNER JOIN happening ON happening.uri = notice.uri ';
$qry .= 'AND notice.is_local <> ' . Notice::GATEWAY . ' ';
$notice->selectAdd();
$notice->selectAdd('notice.*');
if ($since_id != 0) {
$qry .= 'AND notice.id > ' . $since_id . ' ';
}
$notice->joinAdd(['uri', 'happening:uri']);
if ($max_id != 0) {
$qry .= 'AND notice.id <= ' . $max_id . ' ';
}
$notice->whereAdd('notice.is_local <> ' . Notice::GATEWAY);
Notice::addWhereSinceId($notice, $since_id, 'notice.id', 'happening.created');
Notice::addWhereMaxId($notice, $max_id, 'notice.id', 'happening.created');
// NOTE: we sort by event time, not by notice time!
$qry .= 'ORDER BY happening.created DESC ';
$notice->orderBy('happening.created DESC');
if (!is_null($offset)) {
$qry .= "LIMIT $limit OFFSET $offset";
$notice->limit($offset, $limit);
}
$notice->query($qry);
$ids = array();
while ($notice->fetch()) {
$ids[] = $notice->id;
$ids = [];
if ($notice->find()) {
while ($notice->fetch()) {
$ids[] = $notice->id;
}
}
$notice->free();