diff --git a/app/Track.php b/app/Track.php index 51ff35d8..18b1027e 100644 --- a/app/Track.php +++ b/app/Track.php @@ -433,16 +433,7 @@ class Track extends Model public function getFilesize($formatName) { - return Cache::remember($this->getCacheKey('filesize-' . $formatName), 1440, function () use ($formatName) { - $file = $this->getFileFor($formatName); - $size = 0; - - if (is_file($file)) { - $size = filesize($file); - } - - return $size; - }); + return $this->trackFiles()->where('format', $formatName)->first()->filesize; } public function canView($user) diff --git a/app/TrackFile.php b/app/TrackFile.php index 1cccd287..8a1df20d 100644 --- a/app/TrackFile.php +++ b/app/TrackFile.php @@ -24,6 +24,7 @@ use Helpers; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Cache; +use Illuminate\Support\Facades\File; use Illuminate\Support\Facades\URL; class TrackFile extends Model @@ -96,16 +97,7 @@ class TrackFile extends Model protected function getFilesize() { - return Cache::remember($this->getCacheKey('filesize'), 1440, function () { - $file = $this->getFile(); - $size = 0; - - if (is_file($file)) { - $size = filesize($file); - } - - return $size; - }); + return $this->filesize; } public function getDirectory() @@ -134,4 +126,18 @@ class TrackFile extends Model { return 'track_file-' . $this->id . '-' . $key; } + + public function updateFilesize() + { + $file = $this->getFile(); + + if (File::exists($file)) { + $size = File::size($file); + } else { + $size = null; + } + + $this->filesize = $size; + $this->update(); + } }