X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FProfile_list.php;h=17c2ffd4f470c78dcadddb9327d43f0f6ad642c7;hb=3ba4258f9e13d6ba84dd21197782303ac26b28fd;hp=df7bef520198447f345e09c4c6bc4cd4597349b0;hpb=5a2bab07b25443eacc7f5cfde4b9932cdb511e92;p=quix0rs-gnu-social.git diff --git a/classes/Profile_list.php b/classes/Profile_list.php index df7bef5201..17c2ffd4f4 100644 --- a/classes/Profile_list.php +++ b/classes/Profile_list.php @@ -165,57 +165,9 @@ class Profile_list extends Memcached_DataObject function getNotices($offset, $limit, $since_id=null, $max_id=null) { - $ids = Notice::stream(array($this, '_streamDirect'), - array(), - 'profile_tag:notice_ids:' . $this->id, - $offset, $limit, $since_id, $max_id); + $stream = new PeopletagNoticeStream($this); - return Notice::getStreamByIds($ids); - } - - /** - * 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; + return $stream->getNotices($offset, $limit, $since_id, $max_id); } /** @@ -374,6 +326,8 @@ class Profile_list extends Memcached_DataObject Profile_tag::cleanup($this); Profile_tag_subscription::cleanup($this); + self::blow('profile:lists:%d', $this->tagger); + return parent::delete(); } @@ -400,6 +354,7 @@ class Profile_list extends Memcached_DataObject if($orig->tag != $this->tag || $orig->tagger != $this->tagger) { $existing = Profile_list::getByTaggerAndTag($this->tagger, $this->tag); if(!empty($existing)) { + // TRANS: Server exception. throw new ServerException(_('The tag you are trying to rename ' . 'to already exists.')); } @@ -469,18 +424,24 @@ class Profile_list extends Memcached_DataObject function taggedCount($recount=false) { - if (!$recount) { - return $this->tagged_count; - } + $keypart = sprintf('profile_list:tagged_count:%d:%s', + $this->tagger, + $this->tag); - $tags = new Profile_tag(); - $tags->tag = $this->tag; - $tags->tagger = $this->tagger; - $orig = clone($this); - $this->tagged_count = (int) $tags->count('distinct tagged'); - $this->update($orig); + $count = self::cacheGet($keypart); - return $this->tagged_count; + if ($count === false) { + $tags = new Profile_tag(); + + $tags->tag = $this->tag; + $tags->tagger = $this->tagger; + + $count = $tags->count('distinct tagged'); + + self::cacheSet($keypart, $count); + } + + return $count; } /** @@ -494,17 +455,38 @@ class Profile_list extends Memcached_DataObject function subscriberCount($recount=false) { - if ($recount) { - return $this->subscriber_count; + $keypart = sprintf('profile_list:subscriber_count:%d', + $this->id); + + $count = self::cacheGet($keypart); + + if ($count === false) { + + $sub = new Profile_tag_subscription(); + $sub->profile_tag_id = $this->id; + $count = (int) $sub->count('distinct profile_id'); + + self::cacheSet($keypart, $count); } - $sub = new Profile_tag_subscription(); - $sub->profile_tag_id = $this->id; - $orig = clone($this); - $this->subscriber_count = (int) $sub->count('distinct profile_id'); - $this->update($orig); + return $count; + } - return $this->subscriber_count; + /** + * get the cached number of profiles subscribed to this + * people tag, re-count if the argument is true. + * + * @param boolean $recount whether to ignore cache + * + * @return integer count + */ + + function blowNoticeStreamCache($all=false) + { + self::blow('profile_list:notice_ids:%d', $this->id); + if ($all) { + self::blow('profile_list:notice_ids:%d;last', $this->id); + } } /** @@ -600,7 +582,6 @@ class Profile_list extends Memcached_DataObject * @return mixed Profile_list on success, false on fail */ static function saveNew($fields) { - extract($fields); $ptag = new Profile_list(); @@ -608,10 +589,12 @@ class Profile_list extends Memcached_DataObject $ptag->query('BEGIN'); if (empty($tagger)) { + // TRANS: Server exception saving new tag without having a tagger specified. throw new Exception(_('No tagger specified.')); } if (empty($tag)) { + // TRANS: Server exception saving new tag without having a tag specified. throw new Exception(_('No tag specified.')); } @@ -649,6 +632,7 @@ class Profile_list extends Memcached_DataObject if (!$result) { common_log_db_error($ptag, 'INSERT', __FILE__); + // TRANS: Server exception saving new tag. throw new ServerException(_('Could not create profile tag.')); } @@ -658,6 +642,7 @@ class Profile_list extends Memcached_DataObject $result = $ptag->update($orig); if (!$result) { common_log_db_error($ptag, 'UPDATE', __FILE__); + // TRANS: Server exception saving new tag. throw new ServerException(_('Could not set profile tag URI.')); } } @@ -674,6 +659,7 @@ class Profile_list extends Memcached_DataObject $result = $ptag->update($orig); if (!$result) { common_log_db_error($ptag, 'UPDATE', __FILE__); + // TRANS: Server exception saving new tag. throw new ServerException(_('Could not set profile tag mainpage.')); } } @@ -926,4 +912,13 @@ class Profile_list extends Memcached_DataObject return new ArrayWrapper($wrapped); } } + + function insert() + { + $result = parent::insert(); + if ($result) { + self::blow('profile:lists:%d', $this->tagger); + } + return $result; + } }