From 22f6151a1033661c59afbfce3535bb2f00efb3d6 Mon Sep 17 00:00:00 2001 From: Shashi Gowda Date: Wed, 13 Apr 2011 01:26:56 +0530 Subject: [PATCH] Annihilate profile_tag_inbox. --- actions/showprofiletag.php | 21 ++++--- classes/Notice.php | 112 +++++----------------------------- classes/Profile_list.php | 45 -------------- classes/Profile_tag_inbox.php | 27 -------- classes/statusnet.ini | 9 --- classes/statusnet.links.ini | 5 +- lib/peopletagnoticestream.php | 48 ++++++++++----- 7 files changed, 63 insertions(+), 204 deletions(-) delete mode 100644 classes/Profile_tag_inbox.php diff --git a/actions/showprofiletag.php b/actions/showprofiletag.php index 29ecf4788f..10ab457861 100644 --- a/actions/showprofiletag.php +++ b/actions/showprofiletag.php @@ -33,7 +33,7 @@ require_once INSTALLDIR.'/lib/feedlist.php'; class ShowprofiletagAction extends Action { - var $notice, $tagger, $peopletag; + var $notice, $tagger, $peopletag, $userProfile; function isReadOnly($args) { @@ -88,7 +88,12 @@ class ShowprofiletagAction extends Action } $this->page = ($this->arg('page')) ? ($this->arg('page')+0) : 1; - $this->notice = $this->peopletag->getNotices(($this->page-1)*NOTICES_PER_PAGE, NOTICES_PER_PAGE + 1); + $this->userProfile = Profile::current(); + + $stream = new PeopletagNoticeStream($this->peopletag, $this->userProfile); + + $this->notice = $stream->getNotices(($this->page-1)*NOTICES_PER_PAGE, + NOTICES_PER_PAGE + 1); if ($this->page > 1 && $this->notice->N == 0) { // TRANS: Server error when page not found (404). @@ -239,7 +244,7 @@ class ShowprofiletagAction extends Action function showNotices() { if (Event::handle('StartShowProfileTagContent', array($this))) { - $nl = new NoticeList($this->notice, $this); + $nl = new ThreadedNoticeList($this->notice, $this, $this->userProfile); $cnt = $nl->show(); @@ -247,10 +252,12 @@ class ShowprofiletagAction extends Action $this->showEmptyListMessage(); } - $this->pagination( - $this->page > 1, $cnt > NOTICES_PER_PAGE, - $this->page, 'showprofiletag', array('tag' => $this->peopletag->tag, - 'tagger' => $this->tagger->nickname) + $this->pagination($this->page > 1, + $cnt > NOTICES_PER_PAGE, + $this->page, + 'showprofiletag', + array('tag' => $this->peopletag->tag, + 'tagger' => $this->tagger->nickname) ); Event::handle('EndShowProfileTagContent', array($this)); diff --git a/classes/Notice.php b/classes/Notice.php index 70036fa8fb..ada4d495d2 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -545,12 +545,6 @@ class Notice extends Memcached_DataObject $notice->saveKnownGroups($groups); - if (isset($peopletags)) { - $notice->saveProfileTags($peopletags); - } else { - $notice->saveProfileTags(); - } - if (isset($urls)) { $notice->saveKnownUrls($urls); } else { @@ -596,6 +590,11 @@ class Notice extends Memcached_DataObject if (!empty($profile)) { $profile->blowNoticeCount(); } + + $ptags = $this->getProfileTags(); + foreach ($ptags as $ptag) { + $ptag->blowNoticeStreamCache(); + } } /** @@ -618,6 +617,11 @@ class Notice extends Memcached_DataObject // In case we're the first, will need to calc a new root. self::blow('notice:conversation_root:%d', $this->conversation); } + + $ptags = $this->getProfileTags(); + foreach ($ptags as $ptag) { + $ptag->blowNoticeStreamCache(true); + } } /** save all urls in the notice to the db @@ -1030,34 +1034,14 @@ class Notice extends Memcached_DataObject function getProfileTags() { - // Don't save ptags for repeats, for now. - - if (!empty($this->repeat_of)) { - return array(); - } - - // XXX: cache me - - $ptags = array(); - - $ptagi = new Profile_tag_inbox(); - - $ptagi->selectAdd(); - $ptagi->selectAdd('profile_tag_id'); - - $ptagi->notice_id = $this->id; + $profile = $this->getProfile(); + $list = $profile->getOtherTags($profile); + $ptags = array(); - if ($ptagi->find()) { - while ($ptagi->fetch()) { - $profile_list = Profile_list::staticGet('id', $ptagi->profile_tag_id); - if ($profile_list) { - $ptags[] = $profile_list; - } - } + while($list->fetch()) { + $ptags[] = clone($list); } - $ptagi->free(); - return $ptags; } @@ -1173,72 +1157,6 @@ class Notice extends Memcached_DataObject return true; } - /** - * record targets into profile_tag_inbox. - * @return array of Profile_list objects - */ - function saveProfileTags($known=array()) - { - // Don't save ptags for repeats, for now - - if (!empty($this->repeat_of)) { - return array(); - } - - if (is_array($known)) { - $ptags = $known; - } else { - $ptags = array(); - } - - $ptag = new Profile_tag(); - $ptag->tagged = $this->profile_id; - - if($ptag->find()) { - while($ptag->fetch()) { - $plist = Profile_list::getByTaggerAndTag($ptag->tagger, $ptag->tag); - if (!empty($plist)) { - $ptags[] = clone($plist); - } - } - } - - foreach ($ptags as $target) { - $this->addToProfileTagInbox($target); - } - - return $ptags; - } - - function addToProfileTagInbox($plist) - { - $ptagi = Profile_tag_inbox::pkeyGet(array('profile_tag_id' => $plist->id, - 'notice_id' => $this->id)); - - if (empty($ptagi)) { - - $ptagi = new Profile_tag_inbox(); - - $ptagi->query('BEGIN'); - $ptagi->profile_tag_id = $plist->id; - $ptagi->notice_id = $this->id; - $ptagi->created = $this->created; - - $result = $ptagi->insert(); - if (!$result) { - common_log_db_error($ptagi, 'INSERT', __FILE__); - // TRANS: Server exception thrown when saving profile_tag inbox fails. - throw new ServerException(_('Problem saving profile_tag inbox.')); - } - - $ptagi->query('COMMIT'); - - self::blow('profile_tag:notice_ids:%d', $ptagi->profile_tag_id); - } - - return true; - } - /** * Save reply records indicating that this notice needs to be * delivered to the local users with the given URIs. diff --git a/classes/Profile_list.php b/classes/Profile_list.php index bbe892c0d0..cf0a255e75 100644 --- a/classes/Profile_list.php +++ b/classes/Profile_list.php @@ -170,51 +170,6 @@ class Profile_list extends Memcached_DataObject return $stream->getNotices($offset, $limit, $since_id, $max_id); } - /** - * Query notices by users associated with this tag from the database. - * - * @param integer $offset offset - * @param integer $limit maximum no of results - * @param integer $since_id=null since this id - * @param integer $max_id=null maximum id in result - * - * @return array array of notice ids. - */ - - function _streamDirect($offset, $limit, $since_id, $max_id) - { - $inbox = new Profile_tag_inbox(); - - $inbox->profile_tag_id = $this->id; - - $inbox->selectAdd(); - $inbox->selectAdd('notice_id'); - - if ($since_id != 0) { - $inbox->whereAdd('notice_id > ' . $since_id); - } - - if ($max_id != 0) { - $inbox->whereAdd('notice_id <= ' . $max_id); - } - - $inbox->orderBy('notice_id DESC'); - - if (!is_null($offset)) { - $inbox->limit($offset, $limit); - } - - $ids = array(); - - if ($inbox->find()) { - while ($inbox->fetch()) { - $ids[] = $inbox->notice_id; - } - } - - return $ids; - } - /** * Get subscribers (local and remote) to this people tag * Order by reverse chronology diff --git a/classes/Profile_tag_inbox.php b/classes/Profile_tag_inbox.php deleted file mode 100644 index dd517b3088..0000000000 --- a/classes/Profile_tag_inbox.php +++ /dev/null @@ -1,27 +0,0 @@ -profile_tag = $profile_tag; + $this->profile_list = $profile_list; } + /** + * Query notices by users associated with this tag from the database. + * + * @param integer $offset offset + * @param integer $limit maximum no of results + * @param integer $since_id=null since this id + * @param integer $max_id=null maximum id in result + * + * @return array array of notice ids. + */ + function getNoticeIds($offset, $limit, $since_id, $max_id) { - $inbox = new Profile_tag_inbox(); + $notice = new Notice(); - $inbox->profile_tag_id = $this->profile_tag->id; + $notice->selectAdd(); + $notice->selectAdd('notice.id'); - $inbox->selectAdd(); - $inbox->selectAdd('notice_id'); + $ptag = new Profile_tag(); + $ptag->tag = $this->profile_list->tag; + $ptag->tagger = $this->profile_list->tagger; + $notice->joinAdd($ptag); - Notice::addWhereSinceId($inbox, $since_id, 'notice_id'); - Notice::addWhereMaxId($inbox, $max_id, 'notice_id'); + if ($since_id != 0) { + $notice->whereAdd('notice.id > ' . $since_id); + } - $inbox->orderBy('created DESC, notice_id DESC'); + if ($max_id != 0) { + $notice->whereAdd('notice.id <= ' . $max_id); + } + + $notice->orderBy('notice.id DESC'); if (!is_null($offset)) { - $inbox->limit($offset, $limit); + $notice->limit($offset, $limit); } $ids = array(); - - if ($inbox->find()) { - while ($inbox->fetch()) { - $ids[] = $inbox->notice_id; + if ($notice->find()) { + while ($notice->fetch()) { + $ids[] = $notice->id; } } -- 2.39.5