Ticket #1567 - Change max_id to return notices <= ID instead of < ID

This commit is contained in:
Zach Copley 2009-05-29 16:54:24 -07:00
parent eb76a3bbb3
commit 425f9d703c
6 changed files with 25 additions and 25 deletions

View File

@ -75,7 +75,7 @@ class Twitapidirect_messagesAction extends TwitterapiAction
} }
if ($max_id) { if ($max_id) {
$message->whereAdd("id < $max_id"); $message->whereAdd("id <= $max_id");
} }
if ($since_id) { if ($since_id) {

View File

@ -60,7 +60,7 @@ class Fave extends Memcached_DataObject
} }
if ($max_id != 0) { if ($max_id != 0) {
$fav->whereAdd('notice_id < ' . $max_id); $fav->whereAdd('notice_id <= ' . $max_id);
} }
if (!is_null($since)) { if (!is_null($since)) {

View File

@ -426,22 +426,22 @@ class Notice extends Memcached_DataObject
# XXX: too many args; we need to move to named params or even a separate # XXX: too many args; we need to move to named params or even a separate
# class for notice streams # class for notice streams
static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $order=null, $since=null) { static function getStream($qry, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0, $order=null, $since=null) {
if (common_config('memcached', 'enabled')) { if (common_config('memcached', 'enabled')) {
# Skip the cache if this is a since, since_id or before_id qry # Skip the cache if this is a since, since_id or max_id qry
if ($since_id > 0 || $before_id > 0 || $since) { if ($since_id > 0 || $max_id > 0 || $since) {
return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since); return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since);
} else { } else {
return Notice::getCachedStream($qry, $cachekey, $offset, $limit, $order); return Notice::getCachedStream($qry, $cachekey, $offset, $limit, $order);
} }
} }
return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since); return Notice::getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since);
} }
static function getStreamDirect($qry, $offset, $limit, $since_id, $before_id, $order, $since) { static function getStreamDirect($qry, $offset, $limit, $since_id, $max_id, $order, $since) {
$needAnd = false; $needAnd = false;
$needWhere = true; $needWhere = true;
@ -463,7 +463,7 @@ class Notice extends Memcached_DataObject
$qry .= ' notice.id > ' . $since_id; $qry .= ' notice.id > ' . $since_id;
} }
if ($before_id > 0) { if ($max_id > 0) {
if ($needWhere) { if ($needWhere) {
$qry .= ' WHERE '; $qry .= ' WHERE ';
@ -472,7 +472,7 @@ class Notice extends Memcached_DataObject
$qry .= ' AND '; $qry .= ' AND ';
} }
$qry .= ' notice.id < ' . $before_id; $qry .= ' notice.id <= ' . $max_id;
} }
if ($since) { if ($since) {
@ -630,17 +630,17 @@ class Notice extends Memcached_DataObject
} }
} }
function publicStream($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) function publicStream($offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
{ {
$ids = Notice::stream(array('Notice', '_publicStreamDirect'), $ids = Notice::stream(array('Notice', '_publicStreamDirect'),
array(), array(),
'public', 'public',
$offset, $limit, $since_id, $before_id, $since); $offset, $limit, $since_id, $max_id, $since);
return Notice::getStreamByIds($ids); return Notice::getStreamByIds($ids);
} }
function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) function _publicStreamDirect($offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
{ {
$notice = new Notice(); $notice = new Notice();
@ -664,8 +664,8 @@ class Notice extends Memcached_DataObject
$notice->whereAdd('id > ' . $since_id); $notice->whereAdd('id > ' . $since_id);
} }
if ($before_id != 0) { if ($max_id != 0) {
$notice->whereAdd('id < ' . $before_id); $notice->whereAdd('id <= ' . $max_id);
} }
if (!is_null($since)) { if (!is_null($since)) {
@ -998,15 +998,15 @@ class Notice extends Memcached_DataObject
} }
} }
function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $before_id=0, $since=null) function stream($fn, $args, $cachekey, $offset=0, $limit=20, $since_id=0, $max_id=0, $since=null)
{ {
$cache = common_memcache(); $cache = common_memcache();
if (empty($cache) || if (empty($cache) ||
$since_id != 0 || $before_id != 0 || !is_null($since) || $since_id != 0 || $max_id != 0 || !is_null($since) ||
($offset + $limit) > NOTICE_CACHE_WINDOW) { ($offset + $limit) > NOTICE_CACHE_WINDOW) {
return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id, return call_user_func_array($fn, array_merge($args, array($offset, $limit, $since_id,
$before_id, $since))); $max_id, $since)));
} }
$idkey = common_cache_key($cachekey); $idkey = common_cache_key($cachekey);

View File

@ -62,7 +62,7 @@ class Notice_inbox extends Memcached_DataObject
} }
if ($max_id != 0) { if ($max_id != 0) {
$inbox->whereAdd('notice_id < ' . $max_id); $inbox->whereAdd('notice_id <= ' . $max_id);
} }
if (!is_null($since)) { if (!is_null($since)) {

View File

@ -153,18 +153,18 @@ class Profile extends Memcached_DataObject
return null; return null;
} }
function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0) function getNotices($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $max_id=0)
{ {
// XXX: I'm not sure this is going to be any faster. It probably isn't. // XXX: I'm not sure this is going to be any faster. It probably isn't.
$ids = Notice::stream(array($this, '_streamDirect'), $ids = Notice::stream(array($this, '_streamDirect'),
array(), array(),
'profile:notice_ids:' . $this->id, 'profile:notice_ids:' . $this->id,
$offset, $limit, $since_id, $before_id); $offset, $limit, $since_id, $max_id);
return Notice::getStreamByIds($ids); return Notice::getStreamByIds($ids);
} }
function _streamDirect($offset, $limit, $since_id, $before_id, $since) function _streamDirect($offset, $limit, $since_id, $max_id, $since)
{ {
$notice = new Notice(); $notice = new Notice();
@ -177,8 +177,8 @@ class Profile extends Memcached_DataObject
$notice->whereAdd('id > ' . $since_id); $notice->whereAdd('id > ' . $since_id);
} }
if ($before_id != 0) { if ($max_id != 0) {
$notice->whereAdd('id < ' . $before_id); $notice->whereAdd('id <= ' . $max_id);
} }
if (!is_null($since)) { if (!is_null($since)) {

View File

@ -72,7 +72,7 @@ class User_group extends Memcached_DataObject
} }
if ($max_id != 0) { if ($max_id != 0) {
$inbox->whereAdd('notice_id < ' . $max_id); $inbox->whereAdd('notice_id <= ' . $max_id);
} }
if (!is_null($since)) { if (!is_null($since)) {