Notice inboxes
--------------
-Before version 0.6.2, the page showing all notices from people the
-user is subscribed to ("so-and-so with friends") was calculated at run
-time. Starting with 0.6.2, we have a new data structure for holding a
-user's "notice inbox". (Note: distinct from the "message inbox", which
-is the "inbox" tab in the UI. The notice inbox appears under the
-"Personal" tab.)
-
-Notices are added to the inbox when they're created. This speeds up
-the query considerably, and also allows us the opportunity, in the
-future, to add different kind of notices to an inbox -- like @-replies
-or subscriptions to search terms or hashtags.
-
-Notice inboxes are enabled by default for new installations. If you
-are upgrading an existing site, this means that your users will see
-empty "Personal" pages. The following steps will help you fix the
-problem.
-
-0. $config['inboxes']['enabled'] can be set to one of three values. If
- you set it to 'false', the site will work as before. Support for this
- will probably be dropped in future versions.
-1. Setting the flag to 'transitional' means that you're in transition.
- In this mode, the code will run the "new query" or the "old query"
- based on whether the user's inbox has been updated.
-2. After setting the flag to "transitional", you can run the
- fixup_inboxes.php script to create the inboxes. You may want to set
- the memory limit high. You can re-run it without ill effect.
-3. When fixup_inboxes is finished, you can set the enabled flag to
- 'true'.
-
-NOTE: As of version 0.8.1 notice inboxes are automatically trimmed back
- to ~1000 notices every once in a while.
-
-NOTE: we will drop support for non-inboxed sites in the 0.9.x version
-of StatusNet. It's time to switch now!
+Notice inboxes are now required. If you don't have inboxes enabled,
+StatusNet will no longer run.
UTF-8 Database
--------------
For notice inboxes.
-enabled: A three-valued flag for whether to use notice inboxes (see
- upgrading info above for notes about this change). Can be
- 'false', 'true', or '"transitional"'.
+enabled: No longer used. If you set this to something other than true,
+ StatusNet will no longer run.
throttle
--------
{
parent::handle($args);
- if (!common_config('inboxes', 'enabled')) {
- $this->serverError(
- _('Inboxes must be enabled for groups to work'),
- 400,
- $this->format
- );
- return false;
- }
-
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
$this->clientError(
_('This method requires a POST.'),
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
if (!common_logged_in()) {
$this->clientError(_('You must be logged in to create a group.'));
return false;
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
$id = $this->arg('id');
if (!$id) {
{
parent::prepare($args);
- if (!common_config('inboxes', 'enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
if (!common_logged_in()) {
$this->clientError(_('You must be logged in to edit a group.'));
return false;
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
if (!common_logged_in()) {
$this->clientError(_('You must be logged in to create a group.'));
return false;
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
$nickname_arg = $this->arg('nickname');
$nickname = common_canonical_nickname($nickname_arg);
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
if (!common_logged_in()) {
$this->clientError(_('You must be logged in to join a group.'));
return false;
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work.'));
- return false;
- }
-
if (!common_logged_in()) {
$this->clientError(_('You must be logged in to leave a group.'));
return false;
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
if (!common_logged_in()) {
$this->clientError(_('You must be logged in to create a group.'));
return false;
{
parent::prepare($args);
- if (!common_config('inboxes','enabled')) {
- $this->serverError(_('Inboxes must be enabled for groups to work'));
- return false;
- }
-
$this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1;
$nickname_arg = $this->arg('nickname');
'Fave',
'Notice_tag',
'Group_inbox',
- 'Queue_item');
- if (common_config('inboxes', 'enabled')) {
- $related[] = 'Notice_inbox';
- }
+ 'Queue_item',
+ 'Notice_inbox');
+
foreach ($related as $cls) {
$inst = new $cls();
$inst->notice_id = $this->id;
function addToInboxes()
{
- $enabled = common_config('inboxes', 'enabled');
+ // XXX: loads constants
- if ($enabled === true || $enabled === 'transitional') {
+ $inbox = new Notice_inbox();
- // XXX: loads constants
+ $users = $this->getSubscribedUsers();
- $inbox = new Notice_inbox();
+ // FIXME: kind of ignoring 'transitional'...
+ // we'll probably stop supporting inboxless mode
+ // in 0.9.x
- $users = $this->getSubscribedUsers();
+ $ni = array();
- // FIXME: kind of ignoring 'transitional'...
- // we'll probably stop supporting inboxless mode
- // in 0.9.x
+ foreach ($users as $id) {
+ $ni[$id] = NOTICE_INBOX_SOURCE_SUB;
+ }
- $ni = array();
+ $groups = $this->saveGroups();
+ foreach ($groups as $group) {
+ $users = $group->getUserMembers();
foreach ($users as $id) {
- $ni[$id] = NOTICE_INBOX_SOURCE_SUB;
- }
-
- $groups = $this->saveGroups();
-
- foreach ($groups as $group) {
- $users = $group->getUserMembers();
- foreach ($users as $id) {
- if (!array_key_exists($id, $ni)) {
- $ni[$id] = NOTICE_INBOX_SOURCE_GROUP;
- }
+ if (!array_key_exists($id, $ni)) {
+ $ni[$id] = NOTICE_INBOX_SOURCE_GROUP;
}
}
+ }
- $cnt = 0;
-
- $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES ';
- $qry = $qryhdr;
+ $cnt = 0;
- foreach ($ni as $id => $source) {
- if ($cnt > 0) {
- $qry .= ', ';
- }
- $qry .= '('.$id.', '.$this->id.', '.$source.", '".$this->created. "') ";
- $cnt++;
- if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) {
- // FIXME: Causes lag in replicated servers
- // Notice_inbox::gc($id);
- }
- if ($cnt >= MAX_BOXCARS) {
- $inbox = new Notice_inbox();
- $inbox->query($qry);
- $qry = $qryhdr;
- $cnt = 0;
- }
- }
+ $qryhdr = 'INSERT INTO notice_inbox (user_id, notice_id, source, created) VALUES ';
+ $qry = $qryhdr;
+ foreach ($ni as $id => $source) {
if ($cnt > 0) {
+ $qry .= ', ';
+ }
+ $qry .= '('.$id.', '.$this->id.', '.$source.", '".$this->created. "') ";
+ $cnt++;
+ if (rand() % NOTICE_INBOX_SOFT_LIMIT == 0) {
+ // FIXME: Causes lag in replicated servers
+ // Notice_inbox::gc($id);
+ }
+ if ($cnt >= MAX_BOXCARS) {
$inbox = new Notice_inbox();
$inbox->query($qry);
+ $qry = $qryhdr;
+ $cnt = 0;
}
}
+ if ($cnt > 0) {
+ $inbox = new Notice_inbox();
+ $inbox->query($qry);
+ }
+
return;
}
{
$groups = array();
- $enabled = common_config('inboxes', 'enabled');
- if ($enabled !== true && $enabled !== 'transitional') {
- return $groups;
- }
-
/* extract all !group */
$count = preg_match_all('/(?:^|\s)!([A-Za-z0-9]{1,64})/',
strtolower($this->content),
}
}
- $inboxes = common_config('inboxes', 'enabled');
+ // This flag is ignored but still set to 1
- if ($inboxes === true || $inboxes == 'transitional') {
- $user->inboxed = 1;
- }
+ $user->inboxed = 1;
$user->created = common_sql_now();
$user->uri = common_user_uri($user);
function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null)
{
- $enabled = common_config('inboxes', 'enabled');
-
- // Complicated code, depending on whether we support inboxes yet
- // XXX: make this go away when inboxes become mandatory
-
- if ($enabled === false ||
- ($enabled == 'transitional' && $this->inboxed == 0)) {
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
- 'WHERE subscription.subscriber = %d ' .
- 'AND notice.is_local != ' . Notice::GATEWAY;
- return Notice::getStream(sprintf($qry, $this->id),
- 'user:notices_with_friends:' . $this->id,
- $offset, $limit, $since_id, $before_id,
- $order, $since);
- } else if ($enabled === true ||
- ($enabled == 'transitional' && $this->inboxed == 1)) {
-
- $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false);
+ $ids = Notice_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)
{
- $enabled = common_config('inboxes', 'enabled');
-
- // Complicated code, depending on whether we support inboxes yet
- // XXX: make this go away when inboxes become mandatory
+ $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
- if ($enabled === false ||
- ($enabled == 'transitional' && $this->inboxed == 0)) {
- $qry =
- 'SELECT notice.* ' .
- 'FROM notice JOIN subscription ON notice.profile_id = subscription.subscribed ' .
- 'WHERE subscription.subscriber = %d ';
- return Notice::getStream(sprintf($qry, $this->id),
- 'user:notices_with_friends:' . $this->id,
- $offset, $limit, $since_id, $before_id,
- $order, $since);
- } else if ($enabled === true ||
- ($enabled == 'transitional' && $this->inboxed == 1)) {
-
- $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true);
-
- return Notice::getStreamByIds($ids);
- }
+ return Notice::getStreamByIds($ids);
}
function blowFavesCache()
'Remember_me',
'Foreign_link',
'Invitation',
+ 'Notice_inbox',
);
- if (common_config('inboxes', 'enabled')) {
- $related[] = 'Notice_inbox';
- }
-
foreach ($related as $cls) {
$inst = new $cls();
$inst->user_id = $this->id;
'ping' =>
array('notify' => array()),
'inboxes' =>
- array('enabled' => true), # on by default for new sites
+ array('enabled' => true), # ignored after 0.9.x
'newuser' =>
array('default' => null,
'welcome' => null),