summaryrefslogtreecommitdiff
path: root/classes
diff options
context:
space:
mode:
authorEvan Prodromou <evan@controlyourself.ca>2009-04-27 16:55:07 -0400
committerEvan Prodromou <evan@controlyourself.ca>2009-04-27 16:55:07 -0400
commitce5b98ca016841edf920ebc062f1b4d53488762c (patch)
tree2aff0cd2f420a251f24dac7f477a4476b52d3798 /classes
parent3081b2e31708520e6ed83041ce3ba04329d3ec90 (diff)
parent8cf8298dc02b1373fed53eb95982a33b969b42ee (diff)
Merge branch '0.7.x' into querybyid
Diffstat (limited to 'classes')
-rw-r--r--classes/Notice.php84
1 files changed, 68 insertions, 16 deletions
diff --git a/classes/Notice.php b/classes/Notice.php
index 5fa0d79a1..27b98de1c 100644
--- a/classes/Notice.php
+++ b/classes/Notice.php
@@ -197,7 +197,12 @@ class Notice extends Memcached_DataObject
$notice->saveTags();
$notice->saveGroups();
- $notice->addToInboxes();
+ if (common_config('queue', 'enabled')) {
+ $notice->addToAuthorInbox();
+ } else {
+ $notice->addToInboxes();
+ }
+
$notice->query('COMMIT');
Event::handle('EndNoticeSave', array($notice));
@@ -207,7 +212,11 @@ class Notice extends Memcached_DataObject
# XXX: someone clever could prepend instead of clearing the cache
if (common_config('memcached', 'enabled')) {
- $notice->blowCaches();
+ if (common_config('queue', 'enabled')) {
+ $notice->blowAuthorCaches();
+ } else {
+ $notice->blowCaches();
+ }
}
return $notice;
@@ -271,6 +280,17 @@ class Notice extends Memcached_DataObject
$this->blowGroupCache($blowLast);
}
+ function blowAuthorCaches($blowLast=false)
+ {
+ // Clear the user's cache
+ $cache = common_memcache();
+ if (!empty($cache)) {
+ $cache->delete(common_cache_key('user:notices_with_friends:' . $this->profile_id));
+ }
+ $this->blowNoticeCache($blowLast);
+ $this->blowPublicCache($blowLast);
+ }
+
function blowGroupCache($blowLast=false)
{
$cache = common_memcache();
@@ -639,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');
@@ -691,24 +738,29 @@ class Notice extends Memcached_DataObject
// 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);
+ $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) ' .
+ "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);
+ }
+
function saveReplies()
{
// Alternative reply format