From 4d7cdbf1c65f54cd66eb7eab23985d4db0351b63 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 16:26:46 -0800 Subject: don't write Inbox if on a read-only page, but encache --- classes/Inbox.php | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'classes') diff --git a/classes/Inbox.php b/classes/Inbox.php index e14d4f4e7..83cfe8ef8 100644 --- a/classes/Inbox.php +++ b/classes/Inbox.php @@ -56,6 +56,22 @@ class Inbox extends Memcached_DataObject */ static function initialize($user_id) + { + $inbox = Inbox::fromNoticeInbox($user_id); + + unset($inbox->fake); + + $result = $inbox->insert(); + + if (!$result) { + common_log_db_error($inbox, 'INSERT', __FILE__); + return null; + } + + return $inbox; + } + + static function fromNoticeInbox($user_id) { $ids = array(); @@ -80,13 +96,7 @@ class Inbox extends Memcached_DataObject $inbox->user_id = $user_id; $inbox->notice_ids = call_user_func_array('pack', array_merge(array('N*'), $ids)); - - $result = $inbox->insert(); - - if (!$result) { - common_log_db_error($inbox, 'INSERT', __FILE__); - return null; - } + $inbox->fake = true; return $inbox; } @@ -95,7 +105,7 @@ class Inbox extends Memcached_DataObject { $inbox = Inbox::staticGet('user_id', $user_id); - if (empty($inbox)) { + if (empty($inbox) || $inbox->fake) { $inbox = Inbox::initialize($user_id); } @@ -133,9 +143,11 @@ class Inbox extends Memcached_DataObject $inbox = Inbox::staticGet('user_id', $user_id); if (empty($inbox)) { - $inbox = Inbox::initialize($user_id); + $inbox = Inbox::fromNoticeInbox($user_id); if (empty($inbox)) { return array(); + } else { + $inbox->encache(); } } -- cgit v1.2.3-54-g00ecf