X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2FNotice.php;h=650dca051b359727ec00cc64c8f44b07cd280a3e;hb=0502e1d737af1586a7a280be005e55d85c71175a;hp=ba66dd8054440ffd1297f0fd3b2d37e93d5dc5c9;hpb=4fa7f147b070c07d33d38330db65aafc9e1789b8;p=quix0rs-gnu-social.git diff --git a/classes/Notice.php b/classes/Notice.php index ba66dd8054..650dca051b 100644 --- a/classes/Notice.php +++ b/classes/Notice.php @@ -1,7 +1,7 @@ scope = $reply->scope; } else { - $notice->scope = common_config('notice', 'defaultscope'); + $notice->scope = self::defaultScope(); } } else { $notice->scope = $scope; @@ -561,10 +566,10 @@ class Notice extends Memcached_DataObject function blowOnInsert($conversation = false) { - self::blow('profile:notice_ids:%d', $this->profile_id); + $this->blowStream('profile:notice_ids:%d', $this->profile_id); if ($this->isPublic()) { - self::blow('public'); + $this->blowStream('public'); } // XXX: Before we were blowing the casche only if the notice id @@ -574,7 +579,7 @@ class Notice extends Memcached_DataObject self::blow('conversation::notice_count:%d', $this->conversation); if (!empty($this->repeat_of)) { - self::blow('notice:repeats:%d', $this->repeat_of); + $this->blowStream('notice:repeats:%d', $this->repeat_of); } $original = Notice::staticGet('id', $this->repeat_of); @@ -582,11 +587,12 @@ class Notice extends Memcached_DataObject if (!empty($original)) { $originalUser = User::staticGet('id', $original->profile_id); if (!empty($originalUser)) { - self::blow('user:repeats_of_me:%d', $originalUser->id); + $this->blowStream('user:repeats_of_me:%d', $originalUser->id); } } $profile = Profile::staticGet($this->profile_id); + if (!empty($profile)) { $profile->blowNoticeCount(); } @@ -624,6 +630,42 @@ class Notice extends Memcached_DataObject } } + function blowStream() + { + $c = self::memcache(); + + if (empty($c)) { + return false; + } + + $args = func_get_args(); + + $format = array_shift($args); + + $keyPart = vsprintf($format, $args); + + $cacheKey = Cache::key($keyPart); + + $c->delete($cacheKey); + + // delete the "last" stream, too, if this notice is + // older than the top of that stream + + $lastKey = $cacheKey.';last'; + + $lastStr = $c->get($lastKey); + + if ($lastStr !== false) { + $window = explode(',', $lastStr); + $lastID = $window[0]; + $lastNotice = Notice::staticGet('id', $lastID); + if (empty($lastNotice) // just weird + || strtotime($lastNotice->created) >= strtotime($this->created)) { + $c->delete($lastKey); + } + } + } + /** save all urls in the notice to the db * * follow redirects and save all available file information @@ -1819,7 +1861,11 @@ class Notice extends Memcached_DataObject } else { $idstr = $cache->get(Cache::key('notice:repeats:'.$this->id)); if ($idstr !== false) { - $ids = explode(',', $idstr); + if (empty($idstr)) { + $ids = array(); + } else { + $ids = explode(',', $idstr); + } } else { $ids = $this->_repeatStreamDirect(100); $cache->set(Cache::key('notice:repeats:'.$this->id), implode(',', $ids)); @@ -1848,18 +1894,7 @@ class Notice extends Memcached_DataObject $notice->limit(0, $limit); } - $ids = array(); - - if ($notice->find()) { - while ($notice->fetch()) { - $ids[] = $notice->id; - } - } - - $notice->free(); - $notice = NULL; - - return $ids; + return $notice->fetchAll('id'); } function locationOptions($lat, $lon, $location_id, $location_ns, $profile = null) @@ -2432,5 +2467,18 @@ class Notice extends Memcached_DataObject $skip = array('_original', '_profile'); return array_diff($vars, $skip); } + + static function defaultScope() + { + $scope = common_config('notice', 'defaultscope'); + if (is_null($scope)) { + if (common_config('site', 'private')) { + $scope = 1; + } else { + $scope = 0; + } + } + return $scope; + } }