function _streamDirect($offset, $limit, $since_id, $max_id) { $inbox = new Group_inbox(); $inbox->group_id = $this->id; $inbox->selectAdd(); $inbox->selectAdd('notice_id'); if ($since_id != 0) { $inbox->whereAdd('notice_id > ' . $since_id); } if ($max_id != 0) { $inbox->whereAdd('notice_id <= ' . $max_id); } $inbox->orderBy('notice_id DESC'); if (!is_null($offset)) { $inbox->limit($offset, $limit); } $ids = array(); if ($inbox->find()) { while ($inbox->fetch()) { $ids[] = $inbox->notice_id; } } return $ids; }
function clearGroupInboxes() { $gi = new Group_inbox(); $gi->notice_id = $this->id; if ($gi->find()) { while ($gi->fetch()) { self::blow('user_group:notice_ids:%d', $gi->group_id); $gi->delete(); } } $gi->free(); }
public function onHandleQueuedNotice(Notice $notice) { $paths = array(); // Add to the author's timeline try { $profile = $notice->getProfile(); } catch (Exception $e) { $this->log(LOG_ERR, $e->getMessage()); return true; } try { $user = $profile->getUser(); $paths[] = array('showstream', $user->nickname, null); } catch (NoSuchUserException $e) { // We really should handle the remote profile views too $user = null; } // Add to the public timeline $is_local = intval($notice->is_local); if ($is_local === Notice::LOCAL_PUBLIC || $is_local === Notice::REMOTE && !common_config('public', 'localonly')) { $paths[] = array('public', null, null); } // Add to the tags timeline $tags = $this->getNoticeTags($notice); if (!empty($tags)) { foreach ($tags as $tag) { $paths[] = array('tag', $tag, null); } } // Add to inbox timelines // XXX: do a join $ni = $notice->whoGets(); foreach (array_keys($ni) as $user_id) { $user = User::getKV('id', $user_id); $paths[] = array('all', $user->nickname, null); } // Add to the replies timeline $reply = new Reply(); $reply->notice_id = $notice->id; if ($reply->find()) { while ($reply->fetch()) { $user = User::getKV('id', $reply->profile_id); if (!empty($user)) { $paths[] = array('replies', $user->nickname, null); } } } // Add to the group timeline // XXX: join $gi = new Group_inbox(); $gi->notice_id = $notice->id; if ($gi->find()) { while ($gi->fetch()) { $ug = User_group::getKV('id', $gi->group_id); $paths[] = array('showgroup', $ug->nickname, null); } } if (count($paths) > 0) { $json = $this->noticeAsJson($notice); $this->_connect(); // XXX: We should probably fan-out here and do a // new queue item for each path foreach ($paths as $path) { list($action, $arg1, $arg2) = $path; $channels = Realtime_channel::getAllChannels($action, $arg1, $arg2); $this->log(LOG_INFO, sprintf(_("%d candidate channels for notice %d"), count($channels), $notice->id)); foreach ($channels as $channel) { // XXX: We should probably fan-out here and do a // new queue item for each user/path combo if (is_null($channel->user_id)) { $profile = null; } else { $profile = Profile::getKV('id', $channel->user_id); } if ($notice->inScope($profile)) { $this->log(LOG_INFO, sprintf(_("Delivering notice %d to channel (%s, %s, %s) for user '%s'"), $notice->id, $channel->action, $channel->arg1, $channel->arg2, $profile ? $profile->nickname : "<public>")); $timeline = $this->_pathToChannel(array($channel->channel_key)); $this->_publish($timeline, $json); } } } $this->_disconnect(); } return true; }
function onHandleQueuedNotice($notice) { $paths = array(); // Add to the author's timeline $user = User::staticGet('id', $notice->profile_id); if (!empty($user)) { $paths[] = array('showstream', $user->nickname); } // Add to the public timeline if ($notice->is_local == Notice::LOCAL_PUBLIC || $notice->is_local == Notice::REMOTE_OMB && !common_config('public', 'localonly')) { $paths[] = array('public'); } // Add to the tags timeline $tags = $this->getNoticeTags($notice); if (!empty($tags)) { foreach ($tags as $tag) { $paths[] = array('tag', $tag); } } // Add to inbox timelines // XXX: do a join $ni = $notice->whoGets(); foreach (array_keys($ni) as $user_id) { $user = User::staticGet('id', $user_id); $paths[] = array('all', $user->nickname); } // Add to the replies timeline $reply = new Reply(); $reply->notice_id = $notice->id; if ($reply->find()) { while ($reply->fetch()) { $user = User::staticGet('id', $reply->profile_id); if (!empty($user)) { $paths[] = array('replies', $user->nickname); } } } // Add to the group timeline // XXX: join $gi = new Group_inbox(); $gi->notice_id = $notice->id; if ($gi->find()) { while ($gi->fetch()) { $ug = User_group::staticGet('id', $gi->group_id); $paths[] = array('showgroup', $ug->nickname); } } if (count($paths) > 0) { $json = $this->noticeAsJson($notice); $this->_connect(); foreach ($paths as $path) { $timeline = $this->_pathToChannel($path); $this->_publish($timeline, $json); } $this->_disconnect(); } return true; }
function blowGroupCache($blowLast = false) { $cache = common_memcache(); if ($cache) { $group_inbox = new Group_inbox(); $group_inbox->notice_id = $this->id; if ($group_inbox->find()) { while ($group_inbox->fetch()) { $cache->delete(common_cache_key('group:notices:' . $group_inbox->group_id)); if ($blowLast) { $cache->delete(common_cache_key('group:notices:' . $group_inbox->group_id . ';last')); } $member = new Group_member(); $member->group_id = $group_inbox->group_id; if ($member->find()) { while ($member->fetch()) { $cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id)); if ($blowLast) { $cache->delete(common_cache_key('user:notices_with_friends:' . $member->profile_id . ';last')); } } } } } $group_inbox->free(); unset($group_inbox); } }