mirror of
https://github.com/pixelfed/pixelfed.git
synced 2024-11-26 00:03:16 +00:00
Update StatusService, add non-public option and improve cache invalidation
This commit is contained in:
parent
ee0028bc57
commit
15c4fdd90c
2 changed files with 355 additions and 349 deletions
|
@ -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));
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue