Some fixes to make the notice stream class work
This commit is contained in:
parent
efb6a7b441
commit
2b901894c2
@ -87,6 +87,16 @@ class Fave extends Memcached_DataObject
|
|||||||
return $stream->getNotices($offset, $limit, $since_id, $max_id);
|
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*.
|
* Note that the sorting for this is by order of *fave* not order of *notice*.
|
||||||
*
|
*
|
||||||
|
@ -45,7 +45,7 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
|||||||
/* We keep 200 notices, the max number of notices available per API request,
|
/* We keep 200 notices, the max number of notices available per API request,
|
||||||
* in the memcached cache. */
|
* in the memcached cache. */
|
||||||
|
|
||||||
define('NOTICE_CACHE_WINDOW', 200);
|
define('NOTICE_CACHE_WINDOW', NoticeStream::CACHE_WINDOW);
|
||||||
|
|
||||||
define('MAX_BOXCARS', 128);
|
define('MAX_BOXCARS', 128);
|
||||||
|
|
||||||
@ -548,7 +548,7 @@ class Notice extends Memcached_DataObject
|
|||||||
if (empty($profile)) {
|
if (empty($profile)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$notice = $profile->getNotices(0, NOTICE_CACHE_WINDOW);
|
$notice = $profile->getNotices(0, NoticeStream::CACHE_WINDOW);
|
||||||
if (!empty($notice)) {
|
if (!empty($notice)) {
|
||||||
$last = 0;
|
$last = 0;
|
||||||
while ($notice->fetch()) {
|
while ($notice->fetch()) {
|
||||||
@ -1656,7 +1656,7 @@ class Notice extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Notice::getStreamByIds($ids);
|
return NoticeStream::getStreamByIds($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _repeatStreamDirect($limit)
|
function _repeatStreamDirect($limit)
|
||||||
|
@ -550,7 +550,7 @@ class Profile extends Memcached_DataObject
|
|||||||
// This is the stream of favorite notices, in rev chron
|
// This is the stream of favorite notices, in rev chron
|
||||||
// order. This forces it into cache.
|
// 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
|
// If it's in the list, then it's a fave
|
||||||
|
|
||||||
@ -562,7 +562,7 @@ class Profile extends Memcached_DataObject
|
|||||||
// then the cache has all available faves, so this one
|
// then the cache has all available faves, so this one
|
||||||
// is not a fave.
|
// is not a fave.
|
||||||
|
|
||||||
if (count($ids) < NOTICE_CACHE_WINDOW) {
|
if (count($ids) < NoticeStream::CACHE_WINDOW) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,6 +47,8 @@ if (!defined('STATUSNET')) {
|
|||||||
|
|
||||||
class NoticeStream
|
class NoticeStream
|
||||||
{
|
{
|
||||||
|
const CACHE_WINDOW = 200;
|
||||||
|
|
||||||
public $generator = null;
|
public $generator = null;
|
||||||
public $args = null;
|
public $args = null;
|
||||||
public $cachekey = null;
|
public $cachekey = null;
|
||||||
@ -71,13 +73,13 @@ class NoticeStream
|
|||||||
{
|
{
|
||||||
$cache = Cache::instance();
|
$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 the cache won't be hit, just generate directly.
|
||||||
|
|
||||||
if (empty($cache) ||
|
if (empty($cache) ||
|
||||||
$sinceId != 0 || $maxId != 0 ||
|
$sinceId != 0 || $maxId != 0 ||
|
||||||
is_null($limit) ||
|
is_null($limit) ||
|
||||||
($offset + $limit) > NOTICE_CACHE_WINDOW) {
|
($offset + $limit) > self::CACHE_WINDOW) {
|
||||||
return $this->generate($offset, $limit, $sinceId, $maxId);
|
return $this->generate($offset, $limit, $sinceId, $maxId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,7 +107,7 @@ class NoticeStream
|
|||||||
if ($laststr !== false) {
|
if ($laststr !== false) {
|
||||||
$window = explode(',', $laststr);
|
$window = explode(',', $laststr);
|
||||||
$last_id = $window[0];
|
$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);
|
$new_window = array_merge($new_ids, $window);
|
||||||
|
|
||||||
@ -122,7 +124,7 @@ class NoticeStream
|
|||||||
// No cache hits :( Generate directly and stick the results
|
// No cache hits :( Generate directly and stick the results
|
||||||
// into the cache. Note we generate the full cache window.
|
// 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);
|
$windowstr = implode(',', $window);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user