return $stream->getNotices($offset, $limit, $since_id, $max_id);
}
+ function idStream($user_id, $offset=0, $limit=NOTICES_PER_PAGE, $own=false, $since_id=0, $max_id=0)
+ {
+ $stream = new NoticeStream(array('Fave', '_streamDirect'),
+ array($user_id, $own),
+ ($own) ? 'fave:ids_by_user_own:'.$user_id :
+ 'fave:ids_by_user:'.$user_id);
+
+ return $stream->getNoticeIds($offset, $limit, $since_id, $max_id);
+ }
+
/**
* Note that the sorting for this is by order of *fave* not order of *notice*.
*
/* We keep 200 notices, the max number of notices available per API request,
* in the memcached cache. */
-define('NOTICE_CACHE_WINDOW', 200);
+define('NOTICE_CACHE_WINDOW', NoticeStream::CACHE_WINDOW);
define('MAX_BOXCARS', 128);
if (empty($profile)) {
return false;
}
- $notice = $profile->getNotices(0, NOTICE_CACHE_WINDOW);
+ $notice = $profile->getNotices(0, NoticeStream::CACHE_WINDOW);
if (!empty($notice)) {
$last = 0;
while ($notice->fetch()) {
}
}
- return Notice::getStreamByIds($ids);
+ return NoticeStream::getStreamByIds($ids);
}
function _repeatStreamDirect($limit)
// This is the stream of favorite notices, in rev chron
// order. This forces it into cache.
- $ids = Fave::stream($this->id, 0, NOTICE_CACHE_WINDOW);
+ $ids = Fave::idStream($this->id, 0, NoticeStream::CACHE_WINDOW);
// If it's in the list, then it's a fave
// then the cache has all available faves, so this one
// is not a fave.
- if (count($ids) < NOTICE_CACHE_WINDOW) {
+ if (count($ids) < NoticeStream::CACHE_WINDOW) {
return false;
}
class NoticeStream
{
+ const CACHE_WINDOW = 200;
+
public $generator = null;
public $args = null;
public $cachekey = null;
{
$cache = Cache::instance();
- // We cache NOTICE_CACHE_WINDOW elements at the tip of the stream.
+ // We cache self::CACHE_WINDOW elements at the tip of the stream.
// If the cache won't be hit, just generate directly.
if (empty($cache) ||
$sinceId != 0 || $maxId != 0 ||
is_null($limit) ||
- ($offset + $limit) > NOTICE_CACHE_WINDOW) {
+ ($offset + $limit) > self::CACHE_WINDOW) {
return $this->generate($offset, $limit, $sinceId, $maxId);
}
if ($laststr !== false) {
$window = explode(',', $laststr);
$last_id = $window[0];
- $new_ids = $this->generate(0, NOTICE_CACHE_WINDOW, $last_id, 0);
+ $new_ids = $this->generate(0, self::CACHE_WINDOW, $last_id, 0);
$new_window = array_merge($new_ids, $window);
// No cache hits :( Generate directly and stick the results
// into the cache. Note we generate the full cache window.
- $window = $this->generate(0, NOTICE_CACHE_WINDOW, 0, 0);
+ $window = $this->generate(0, self::CACHE_WINDOW, 0, 0);
$windowstr = implode(',', $window);