Update StatusService, add non-public option and improve cache invalidation

This commit is contained in:
Daniel Supernault 2021-07-26 19:02:11 -06:00
parent ee0028bc57
commit 15c4fdd90c
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7
2 changed files with 355 additions and 349 deletions

View file

@ -21,10 +21,14 @@ class StatusService {
return self::CACHE_KEY . $id; return self::CACHE_KEY . $id;
} }
public static function get($id) public static function get($id, $publicOnly = true)
{ {
return Cache::remember(self::key($id), now()->addDays(7), function() use($id) { return Cache::remember(self::key($id), now()->addDays(7), function() use($id, $publicOnly) {
if($publicOnly) {
$status = Status::whereScope('public')->find($id); $status = Status::whereScope('public')->find($id);
} else {
$status = Status::whereIn('scope', ['public', 'private', 'unlisted'])->find($id);
}
if(!$status) { if(!$status) {
return null; return null;
} }
@ -37,6 +41,8 @@ class StatusService {
public static function del($id) public static function del($id)
{ {
Cache::forget('pf:services:sh:id:' . $id);
Cache::forget('status:transformer:media:attachments:' . $id);
PublicTimelineService::rem($id); PublicTimelineService::rem($id);
return Cache::forget(self::key($id)); return Cache::forget(self::key($id));
} }

View file

@ -101,10 +101,10 @@ class Status extends Model
}); });
} }
public function url() public function url($forceLocal = false)
{ {
if($this->uri) { if($this->uri) {
return $this->uri; return $forceLocal ? "/i/web/post/_/{$this->profile_id}/{$this->id}" : $this->uri;
} else { } else {
$id = $this->id; $id = $this->id;
$username = $this->profile->username; $username = $this->profile->username;