insert into user's inbox at Web time

This commit is contained in:
Evan Prodromou 2009-04-23 10:38:51 +00:00
parent 1c0d82de3b
commit a9df5eab10

View File

@ -197,7 +197,9 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
$notice->saveGroups();
if (!common_config('queue', 'enabled')) {
if (common_config('queue', 'enabled')) {
$notice->addToAuthorInbox();
} else {
$notice->addToInboxes();
}
@ -282,16 +284,8 @@ class Notice extends Memcached_DataObject
{
// Clear the user's cache
$cache = common_memcache();
if ($cache) {
$user = User::staticGet($this->profile_id);
if (!empty($user)) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id));
if ($blowLast) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $user->id . ';last'));
}
}
$user->free();
unset($user);
if (!empty($cache)) {
$cache->delete(common_cache_key('user:notices_with_friends:' . $this->profile_id));
}
$this->blowNoticeCache($blowLast);
$this->blowPublicCache($blowLast);
@ -665,6 +659,33 @@ class Notice extends Memcached_DataObject
return;
}
function addToAuthorInbox()
{
$enabled = common_config('inboxes', 'enabled');
if ($enabled === true || $enabled === 'transitional') {
$user = User::staticGet('id', $this->profile_id);
if (empty($user)) {
return;
}
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created) ' .
"SELECT $UT.id, " . $this->id . ", '" . $this->created . "' " .
"FROM $UT " .
"WHERE $UT.id = " . $this->profile_id . ' ' .
'AND NOT EXISTS (SELECT user_id, notice_id ' .
'FROM notice_inbox ' .
"WHERE user_id = " . $this->profile_id . ' '.
'AND notice_id = ' . $this->id . ' )';
if ($enabled === 'transitional') {
$qry .= " AND $UT.inboxed = 1";
}
$inbox->query($qry);
}
return;
}
function saveGroups()
{
$enabled = common_config('inboxes', 'enabled');
@ -717,6 +738,13 @@ class Notice extends Memcached_DataObject
// FIXME: do this in an offline daemon
$this->addToGroupInboxes($group);
}
}
}
function addToGroupInboxes($group)
{
$inbox = new Notice_inbox();
$UT = common_config('db','type')=='pgsql'?'"user"':'user';
$qry = 'INSERT INTO notice_inbox (user_id, notice_id, created, source) ' .
@ -732,8 +760,6 @@ class Notice extends Memcached_DataObject
}
$result = $inbox->query($qry);
}
}
}
function saveReplies()
{