From f2a403589cc8858ec3d3ce70f09709f36277c348 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 30 Dec 2009 09:06:07 -1000 Subject: Use inbox instead of notice_inbox --- classes/User.php | 81 ++++++++++++-------------------------------------------- 1 file changed, 17 insertions(+), 64 deletions(-) (limited to 'classes/User.php') diff --git a/classes/User.php b/classes/User.php index 34151778c..773723da4 100644 --- a/classes/User.php +++ b/classes/User.php @@ -291,6 +291,19 @@ class User extends Memcached_DataObject return false; } + // Everyone gets an inbox + + $inbox = new Inbox(); + + $inbox->user_id = $user->id; + + $result = $inbox->insert(); + + if (!$result) { + common_log_db_error($inbox, 'INSERT', __FILE__); + return false; + } + // Everyone is subscribed to themself $subscription = new Subscription(); @@ -482,89 +495,30 @@ class User extends Memcached_DataObject function noticesWithFriends($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); - + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); return Notice::getStreamByIds($ids); } function noticeInbox($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $ids = Notice_inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); - + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); return Notice::getStreamByIds($ids); } function friendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $ids = Notice::stream(array($this, '_friendsTimelineDirect'), - array(false), - 'user:friends_timeline:'.$this->id, - $offset, $limit, $since_id, $before_id, $since); + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, false); return Notice::getStreamByIds($ids); } function ownFriendsTimeline($offset=0, $limit=NOTICES_PER_PAGE, $since_id=0, $before_id=0, $since=null) { - $ids = Notice::stream(array($this, '_friendsTimelineDirect'), - array(true), - 'user:friends_timeline_own:'.$this->id, - $offset, $limit, $since_id, $before_id, $since); + $ids = Inbox::stream($this->id, $offset, $limit, $since_id, $before_id, $since, true); return Notice::getStreamByIds($ids); } - function _friendsTimelineDirect($own, $offset, $limit, $since_id, $max_id, $since) - { - $qry = - 'SELECT notice.id AS id ' . - 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' . - 'WHERE notice_inbox.user_id = ' . $this->id . ' ' . - 'AND notice.repeat_of IS NULL '; - - if (!$own) { - // XXX: autoload notice inbox for constant - $inbox = new Notice_inbox(); - - $qry .= 'AND notice_inbox.source != ' . NOTICE_INBOX_SOURCE_GATEWAY . ' '; - } - - if ($since_id != 0) { - $qry .= 'AND notice.id > ' . $since_id . ' '; - } - - if ($max_id != 0) { - $qry .= 'AND notice.id <= ' . $max_id . ' '; - } - - if (!is_null($since)) { - $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' '; - } - - // NOTE: we sort by fave time, not by notice time! - - $qry .= 'ORDER BY notice_id DESC '; - - if (!is_null($offset)) { - $qry .= "LIMIT $limit OFFSET $offset"; - } - - $ids = array(); - - $notice = new Notice(); - - $notice->query($qry); - - while ($notice->fetch()) { - $ids[] = $notice->id; - } - - $notice->free(); - $notice = NULL; - - return $ids; - } - function blowFavesCache() { $cache = common_memcache(); @@ -777,7 +731,6 @@ class User extends Memcached_DataObject 'Remember_me', 'Foreign_link', 'Invitation', - 'Notice_inbox', ); Event::handle('UserDeleteRelated', array($this, &$related)); -- cgit v1.2.3-54-g00ecf From 1e7ec69190e089f89b57181d561e2df2c8bdd3b5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Thu, 31 Dec 2009 09:09:07 -1000 Subject: some formatting changes to make inblobs work --- classes/Inbox.php | 8 +++++--- classes/User.php | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'classes/User.php') diff --git a/classes/Inbox.php b/classes/Inbox.php index de48d7381..610b5fceb 100644 --- a/classes/Inbox.php +++ b/classes/Inbox.php @@ -56,7 +56,7 @@ class Inbox extends Memcached_DataObject $inbox = new Inbox(); $inbox->query(sprintf('UPDATE inbox '. - 'set notice_ids = concat(cast(%08x as binary(4)), '. + 'set notice_ids = concat(cast(0x%08x as binary(4)), '. 'substr(notice_ids, 1, 4092)) '. 'WHERE user_id = %d', $notice_id, $user_id)); @@ -77,7 +77,7 @@ class Inbox extends Memcached_DataObject $inbox = new Inbox(); $inbox->query(sprintf('UPDATE inbox '. - 'set notice_ids = concat(cast(%08x as binary(4)), '. + 'set notice_ids = concat(cast(0x%08x as binary(4)), '. 'substr(notice_ids, 1, 4092)) '. 'WHERE user_id in (%s)', $notice_id, implode(',', $boxcar))); @@ -94,11 +94,13 @@ class Inbox extends Memcached_DataObject return array(); } - $ids = unpack('L*', $inbox->notice_ids); + $ids = unpack('N*', $inbox->notice_ids); // XXX: handle since_id // XXX: handle max_id $ids = array_slice($ids, $offset, $limit); + + return $ids; } } diff --git a/classes/User.php b/classes/User.php index 773723da4..bde3f71b9 100644 --- a/classes/User.php +++ b/classes/User.php @@ -296,6 +296,7 @@ class User extends Memcached_DataObject $inbox = new Inbox(); $inbox->user_id = $user->id; + $inbox->notice_ids = ''; $result = $inbox->insert(); -- cgit v1.2.3-54-g00ecf From 1bbd19169f22b9405b4ee1964da7e94a228a8dd5 Mon Sep 17 00:00:00 2001 From: Evan Prodromou Date: Wed, 13 Jan 2010 00:44:29 -0800 Subject: unimplement repeatedToMe() until we figure out how --- classes/User.php | 51 +-------------------------------------------------- 1 file changed, 1 insertion(+), 50 deletions(-) (limited to 'classes/User.php') diff --git a/classes/User.php b/classes/User.php index bde3f71b9..d6b52be01 100644 --- a/classes/User.php +++ b/classes/User.php @@ -899,56 +899,7 @@ class User extends Memcached_DataObject function repeatedToMe($offset=0, $limit=20, $since_id=null, $max_id=null) { - $ids = Notice::stream(array($this, '_repeatedToMeDirect'), - array(), - 'user:repeated_to_me:'.$this->id, - $offset, $limit, $since_id, $max_id, null); - - return Notice::getStreamByIds($ids); - } - - function _repeatedToMeDirect($offset, $limit, $since_id, $max_id, $since) - { - $qry = - 'SELECT notice.id AS id ' . - 'FROM notice JOIN notice_inbox ON notice.id = notice_inbox.notice_id ' . - 'WHERE notice_inbox.user_id = ' . $this->id . ' ' . - 'AND notice.repeat_of IS NOT NULL '; - - if ($since_id != 0) { - $qry .= 'AND notice.id > ' . $since_id . ' '; - } - - if ($max_id != 0) { - $qry .= 'AND notice.id <= ' . $max_id . ' '; - } - - if (!is_null($since)) { - $qry .= 'AND notice.modified > \'' . date('Y-m-d H:i:s', $since) . '\' '; - } - - // NOTE: we sort by fave time, not by notice time! - - $qry .= 'ORDER BY notice.id DESC '; - - if (!is_null($offset)) { - $qry .= "LIMIT $limit OFFSET $offset"; - } - - $ids = array(); - - $notice = new Notice(); - - $notice->query($qry); - - while ($notice->fetch()) { - $ids[] = $notice->id; - } - - $notice->free(); - $notice = NULL; - - return $ids; + throw new Exception("Not implemented since inbox change."); } function shareLocation() -- cgit v1.2.3-54-g00ecf