Beispiel #1
0
define('INSTALLDIR', realpath(dirname(__FILE__) . '/..'));
define('LACONICA', true);
require_once INSTALLDIR . '/lib/common.php';
$start_at = $argc > 1 ? $argv[1] : null;
common_log(LOG_INFO, 'Updating user inboxes.');
$user = new User();
if ($start_at) {
    $user->whereAdd('id >= ' . $start_at);
}
$cnt = $user->find();
$cache = common_memcache();
while ($user->fetch()) {
    common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
    $user->query('BEGIN');
    $inbox = new Notice_inbox();
    $result = $inbox->query('INSERT LOW_PRIORITY INTO notice_inbox (user_id, notice_id, created) ' . 'SELECT ' . $user->id . ', notice.id, notice.created ' . 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . 'WHERE subscription.subscriber = ' . $user->id . ' ' . 'AND notice.created >= subscription.created ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . 'WHERE user_id = ' . $user->id . ' ' . 'AND notice_id = notice.id)');
    if (is_null($result) || $result === false) {
        common_log_db_error($inbox, 'INSERT', __FILE__);
        continue;
    }
    $orig = clone $user;
    $user->inboxed = 1;
    $result = $user->update($orig);
    if (!$result) {
        common_log_db_error($user, 'UPDATE', __FILE__);
        continue;
    }
    $user->query('COMMIT');
    $inbox->free();
    unset($inbox);
    if ($cache) {
Beispiel #2
0
 if ($user->inboxed) {
     common_log(LOG_WARNING, 'Already inboxed: ' . $id);
     continue;
 }
 common_log(LOG_INFO, 'Updating inbox for user ' . $user->id);
 $user->query('BEGIN');
 $old_inbox = new Notice_inbox();
 $old_inbox->user_id = $user->id;
 $result = $old_inbox->delete();
 if (is_null($result) || $result === false) {
     common_log_db_error($old_inbox, 'DELETE', __FILE__);
     continue;
 }
 $old_inbox->free();
 $inbox = new Notice_inbox();
 $result = $inbox->query('INSERT INTO notice_inbox (user_id, notice_id, created) ' . 'SELECT ' . $user->id . ', notice.id, notice.created ' . 'FROM subscription JOIN notice ON subscription.subscribed = notice.profile_id ' . 'WHERE subscription.subscriber = ' . $user->id . ' ' . 'AND notice.created >= subscription.created ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . 'WHERE user_id = ' . $user->id . ' ' . 'AND notice_id = notice.id) ' . 'ORDER BY notice.created DESC ' . 'LIMIT 0, 1000');
 if (is_null($result) || $result === false) {
     common_log_db_error($inbox, 'INSERT', __FILE__);
     continue;
 }
 $orig = clone $user;
 $user->inboxed = 1;
 $result = $user->update($orig);
 if (!$result) {
     common_log_db_error($user, 'UPDATE', __FILE__);
     continue;
 }
 $user->query('COMMIT');
 $inbox->free();
 unset($inbox);
 if ($cache) {
Beispiel #3
0
if (!empty($id)) {
    $user->whereAdd('id > ' . $id);
}
$cnt = $user->find();
while ($user->fetch()) {
    $inbox_entry = new Notice_inbox();
    $inbox_entry->user_id = $user->id;
    $inbox_entry->orderBy('created DESC');
    $inbox_entry->limit(1000, 1);
    $id = null;
    if ($inbox_entry->find(true)) {
        $id = $inbox_entry->notice_id;
    }
    $inbox_entry->free();
    unset($inbox_entry);
    if (is_null($id)) {
        continue;
    }
    $start = microtime(true);
    $old_inbox = new Notice_inbox();
    $cnt = $old_inbox->query('DELETE from notice_inbox WHERE user_id = ' . $user->id . ' AND notice_id < ' . $id);
    $old_inbox->free();
    unset($old_inbox);
    print "Deleted {$cnt} notices for {$user->nickname} ({$user->id}).\n";
    $finish = microtime(true);
    $delay = 3.0 * ($finish - $start);
    print "Delaying {$delay} seconds...";
    // Wait to let slaves catch up
    usleep($delay * 1000000);
    print "DONE.\n";
}
Beispiel #4
0
 function saveGroups()
 {
     $enabled = common_config('inboxes', 'enabled');
     if ($enabled !== true && $enabled !== 'transitional') {
         return;
     }
     /* extract all !group */
     $count = preg_match_all('/(?:^|\\s)!([A-Za-z0-9]{1,64})/', strtolower($this->content), $match);
     if (!$count) {
         return true;
     }
     $profile = $this->getProfile();
     /* Add them to the database */
     foreach (array_unique($match[1]) as $nickname) {
         /* XXX: remote groups. */
         $group = User_group::staticGet('nickname', $nickname);
         if (!$group) {
             continue;
         }
         // we automatically add a tag for every group name, too
         $tag = Notice_tag::pkeyGet(array('tag' => common_canonical_tag($nickname), 'notice_id' => $this->id));
         if (is_null($tag)) {
             $this->saveTag($nickname);
         }
         if ($profile->isMember($group)) {
             $gi = new Group_inbox();
             $gi->group_id = $group->id;
             $gi->notice_id = $this->id;
             $gi->created = common_sql_now();
             $result = $gi->insert();
             if (!$result) {
                 common_log_db_error($gi, 'INSERT', __FILE__);
             }
             // FIXME: do this in an offline daemon
             $inbox = new Notice_inbox();
             $UT = common_config('db', 'type') == 'pgsql' ? '"user"' : 'user';
             $qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' . "SELECT {$UT}.id, " . $this->id . ", '" . $this->created . "', 2 " . "FROM {$UT} JOIN group_member ON {$UT}.id = group_member.profile_id " . 'WHERE group_member.group_id = ' . $group->id . ' ' . 'AND NOT EXISTS (SELECT user_id, notice_id ' . 'FROM notice_inbox ' . "WHERE user_id = {$UT}.id " . 'AND notice_id = ' . $this->id . ' )';
             if ($enabled === 'transitional') {
                 $qry .= " AND {$UT}.inboxed = 1";
             }
             $result = $inbox->query($qry);
         }
     }
 }