Update MediaService

This commit is contained in:
Daniel Supernault 2021-08-31 00:38:27 -06:00
parent 427f9da33e
commit 450154e5af
No known key found for this signature in database
GPG key ID: 0DEF1C662C9033F7

View file

@ -18,12 +18,13 @@ class MediaService
public static function get($statusId) public static function get($statusId)
{ {
return Cache::remember(self::CACHE_KEY.$statusId, 129600, function() use($statusId) { $status = Status::find($statusId);
$status = Status::find($statusId); $ttl = $status->created_at->lt(now()->subMinutes(30)) ? 129600 : 30;
return Cache::remember(self::CACHE_KEY.$statusId, $ttl, function() use($status) {
if(!$status) { if(!$status) {
return []; return [];
} }
if(in_array($status->type, ['photo', 'video', 'video:album', 'photo:album', 'loop', 'photo:video:album'])) { if(in_array($status->type, ['group:post', 'photo', 'video', 'video:album', 'photo:album', 'loop', 'photo:video:album'])) {
$media = Media::whereStatusId($status->id)->orderBy('order')->get(); $media = Media::whereStatusId($status->id)->orderBy('order')->get();
$fractal = new Fractal\Manager(); $fractal = new Fractal\Manager();
$fractal->setSerializer(new ArraySerializer()); $fractal->setSerializer(new ArraySerializer());
@ -46,7 +47,7 @@ class MediaService
return []; return [];
} }
return collect($status)->map(function($s) use($license) { return collect($status)->map(function($s) {
$license = isset($s['license']) && $s['license']['title'] ? $s['license']['title'] : null; $license = isset($s['license']) && $s['license']['title'] ? $s['license']['title'] : null;
return [ return [
'type' => 'Document', 'type' => 'Document',