X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=classes%2FProfile_list.php;h=0586a8688c9d20fbe9bd10d6652dd0ce978924ac;hb=efb7d28d830b1057cc0e57496dcb263955bbb358;hp=df7bef520198447f345e09c4c6bc4cd4597349b0;hpb=ced00cf0bdd4f119e2126e2eba18a3df7ee45c11;p=quix0rs-gnu-social.git diff --git a/classes/Profile_list.php b/classes/Profile_list.php index df7bef5201..0586a8688c 100644 --- a/classes/Profile_list.php +++ b/classes/Profile_list.php @@ -49,7 +49,7 @@ class Profile_list extends Memcached_DataObject public $subscriber_count; // smallint /* Static get */ - function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('Profile_list',$k,$v); } + function staticGet($k,$v=NULL) { return Memcached_DataObject::staticGet('Profile_list',$k,$v); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE @@ -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); } /** @@ -233,10 +185,12 @@ class Profile_list extends Memcached_DataObject function getSubscribers($offset=0, $limit=null, $since=0, $upto=0) { $subs = new Profile(); - $sub = new Profile_tag_subscription(); - $sub->profile_tag_id = $this->id; - $subs->joinAdd($sub); + $subs->joinAdd( + array('id', 'profile_tag_subscription:profile_id') + ); + $subs->whereAdd('profile_tag_subscription.profile_tag_id = ' . $this->id); + $subs->selectAdd('unix_timestamp(profile_tag_subscription.' . 'created) as "cursor"'); @@ -374,6 +328,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 +356,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 +426,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); + + $count = self::cacheGet($keypart); + + if ($count === false) { + $tags = new Profile_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); + $tags->tag = $this->tag; + $tags->tagger = $this->tagger; - return $this->tagged_count; + $count = $tags->count('distinct tagged'); + + self::cacheSet($keypart, $count); + } + + return $count; } /** @@ -494,17 +457,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 +584,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 +591,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 +634,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 +644,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 +661,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 +914,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; + } }