Use inbox instead of notice_inbox
This commit is contained in:
parent
7ec27b657e
commit
f2a403589c
@ -31,6 +31,8 @@ require_once INSTALLDIR.'/classes/Memcached_DataObject.php';
|
|||||||
|
|
||||||
class Inbox extends Memcached_DataObject
|
class Inbox extends Memcached_DataObject
|
||||||
{
|
{
|
||||||
|
const BOXCAR = 128;
|
||||||
|
|
||||||
###START_AUTOCODE
|
###START_AUTOCODE
|
||||||
/* the code below is auto generated do not remove the above tag */
|
/* the code below is auto generated do not remove the above tag */
|
||||||
|
|
||||||
@ -48,4 +50,55 @@ class Inbox extends Memcached_DataObject
|
|||||||
{
|
{
|
||||||
return array(false, false, false);
|
return array(false, false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static function insertNotice($user_id, $notice_id)
|
||||||
|
{
|
||||||
|
$inbox = new Inbox();
|
||||||
|
|
||||||
|
$inbox->query(sprintf('UPDATE inbox '.
|
||||||
|
'set notice_ids = concat(cast(%08x as binary(4)), '.
|
||||||
|
'substr(notice_ids, 1, 4092)) '.
|
||||||
|
'WHERE user_id = %d',
|
||||||
|
$notice_id, $user_id));
|
||||||
|
}
|
||||||
|
|
||||||
|
static function bulkInsert($notice_id, $user_ids)
|
||||||
|
{
|
||||||
|
$cnt = count($user_ids);
|
||||||
|
|
||||||
|
for ($off = 0; $off < $cnt; $off += self::BOXCAR) {
|
||||||
|
|
||||||
|
$boxcar = array_slice($user_ids, $off, self::BOXCAR);
|
||||||
|
|
||||||
|
if (empty($boxcar)) { // jump in, hobo!
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$inbox = new Inbox();
|
||||||
|
|
||||||
|
$inbox->query(sprintf('UPDATE inbox '.
|
||||||
|
'set notice_ids = concat(cast(%08x as binary(4)), '.
|
||||||
|
'substr(notice_ids, 1, 4092)) '.
|
||||||
|
'WHERE user_id in (%s)',
|
||||||
|
$notice_id, implode(',', $boxcar)));
|
||||||
|
|
||||||
|
$inbox->free();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function stream($user_id, $offset, $limit, $since_id, $max_id, $since, $own=false)
|
||||||
|
{
|
||||||
|
$inbox = Inbox::staticGet('user_id', $user_id);
|
||||||
|
|
||||||
|
if (empty($inbox)) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
|
||||||
|
$ids = unpack('L*', $inbox->notice_ids);
|
||||||
|
|
||||||
|
// XXX: handle since_id
|
||||||
|
// XXX: handle max_id
|
||||||
|
|
||||||
|
$ids = array_slice($ids, $offset, $limit);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,8 +125,7 @@ class Notice extends Memcached_DataObject
|
|||||||
'Fave',
|
'Fave',
|
||||||
'Notice_tag',
|
'Notice_tag',
|
||||||
'Group_inbox',
|
'Group_inbox',
|
||||||
'Queue_item',
|
'Queue_item');
|
||||||
'Notice_inbox');
|
|
||||||
|
|
||||||
foreach ($related as $cls) {
|
foreach ($related as $cls) {
|
||||||
$inst = new $cls();
|
$inst = new $cls();
|
||||||
@ -504,17 +503,6 @@ class Notice extends Memcached_DataObject
|
|||||||
unset($original);
|
unset($original);
|
||||||
}
|
}
|
||||||
|
|
||||||
$ni = new Notice_inbox();
|
|
||||||
|
|
||||||
$ni->notice_id = $this->id;
|
|
||||||
|
|
||||||
if ($ni->find()) {
|
|
||||||
while ($ni->fetch()) {
|
|
||||||
$tmk = common_cache_key('user:repeated_to_me:'.$ni->user_id);
|
|
||||||
$cache->delete($tmk);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$ni->free();
|
$ni->free();
|
||||||
unset($ni);
|
unset($ni);
|
||||||
}
|
}
|
||||||
@ -844,10 +832,6 @@ class Notice extends Memcached_DataObject
|
|||||||
|
|
||||||
function addToInboxes()
|
function addToInboxes()
|
||||||
{
|
{
|
||||||
// XXX: loads constants
|
|
||||||
|
|
||||||
$inbox = new Notice_inbox();
|
|
||||||
|
|
||||||
$users = $this->getSubscribedUsers();
|
$users = $this->getSubscribedUsers();
|
||||||
|
|
||||||
// FIXME: kind of ignoring 'transitional'...
|
// FIXME: kind of ignoring 'transitional'...
|
||||||
@ -887,7 +871,7 @@ class Notice extends Memcached_DataObject
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Notice_inbox::bulkInsert($this->id, $this->created, $ni);
|
Inbox::bulkInsert($this->id, array_keys($ni));
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -291,6 +291,19 @@ class User extends Memcached_DataObject
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Everyone gets an inbox
|
||||||
|
|
||||||
|
$inbox = new Inbox();
|
||||||
|
|
||||||
|
$inbox->user_id = $user->id;
|
||||||
|
|
||||||
|
$result = $inbox->insert();
|
||||||
|
|
||||||
|
if (!$result) {
|
||||||
|
common_log_db_error($inbox, 'INSERT', __FILE__);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Everyone is subscribed to themself
|
// Everyone is subscribed to themself
|
||||||
|
|
||||||
$subscription = new Subscription();
|
$subscription = new Subscription();
|
||||||
@ -482,89 +495,30 @@ class User extends Memcached_DataObject
|
|||||||
|
|
||||||
function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
||||||
{
|
{
|
||||||
$ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
|
$ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
|
||||||
|
|
||||||
return Notice::getStreamByIds($ids);
|
return Notice::getStreamByIds($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
||||||
{
|
{
|
||||||
$ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
|
$ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
|
||||||
|
|
||||||
return Notice::getStreamByIds($ids);
|
return Notice::getStreamByIds($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
||||||
{
|
{
|
||||||
$ids = Notice::stream(array($this, '_friendsTimelineDirect'),
|
$ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
|
||||||
array(false),
|
|
||||||
'user:friends_timeline:'.$this->id,
|
|
||||||
$offset, $limit, $since_id, $before_id, $since);
|
|
||||||
|
|
||||||
return Notice::getStreamByIds($ids);
|
return Notice::getStreamByIds($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
|
||||||
{
|
{
|
||||||
$ids = Notice::stream(array($this, '_friendsTimelineDirect'),
|
$ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
|
||||||
array(true),
|
|
||||||
'user:friends_timeline_own:'.$this->id,
|
|
||||||
$offset, $limit, $since_id, $before_id, $since);
|
|
||||||
|
|
||||||
return Notice::getStreamByIds($ids);
|
return Notice::getStreamByIds($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _friendsTimelineDirect($own, $offset, $limit, $since_id, $max_id, $since)
|
|
||||||
{
|
|
||||||
$qry =
|
|
||||||
'SELECT notice.id AS id ' .
|
|
||||||
'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' .
|
|
||||||
'WHERE notice_inbox.user_id = ' . $this->id . ' ' .
|
|
||||||
'AND notice.repeat_of IS NULL ';
|
|
||||||
|
|
||||||
if (!$own) {
|
|
||||||
// XXX: autoload notice inbox for constant
|
|
||||||
$inbox = new Notice_inbox();
|
|
||||||
|
|
||||||
$qry .= 'AND notice_inbox.source != ' . NOTICE_INBOX_SOURCE_GATEWAY . ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($since_id != 0) {
|
|
||||||
$qry .= 'AND notice.id > ' . $since_id . ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($max_id != 0) {
|
|
||||||
$qry .= 'AND notice.id <= ' . $max_id . ' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!is_null($since)) {
|
|
||||||
$qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' ';
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: we sort by fave time, not by notice time!
|
|
||||||
|
|
||||||
$qry .= 'ORDER BY notice_id DESC ';
|
|
||||||
|
|
||||||
if (!is_null($offset)) {
|
|
||||||
$qry .= "LIMIT $limit OFFSET $offset";
|
|
||||||
}
|
|
||||||
|
|
||||||
$ids = array();
|
|
||||||
|
|
||||||
$notice = new Notice();
|
|
||||||
|
|
||||||
$notice->query($qry);
|
|
||||||
|
|
||||||
while ($notice->fetch()) {
|
|
||||||
$ids[] = $notice->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
$notice->free();
|
|
||||||
$notice = NULL;
|
|
||||||
|
|
||||||
return $ids;
|
|
||||||
}
|
|
||||||
|
|
||||||
function blowFavesCache()
|
function blowFavesCache()
|
||||||
{
|
{
|
||||||
$cache = common_memcache();
|
$cache = common_memcache();
|
||||||
@ -777,7 +731,6 @@ class User extends Memcached_DataObject
|
|||||||
'Remember_me',
|
'Remember_me',
|
||||||
'Foreign_link',
|
'Foreign_link',
|
||||||
'Invitation',
|
'Invitation',
|
||||||
'Notice_inbox',
|
|
||||||
);
|
);
|
||||||
Event::handle('UserDeleteRelated', array($this, &$related));
|
Event::handle('UserDeleteRelated', array($this, &$related));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user