mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-25 06:27:59 +01:00
Update file size caching for tracks
This commit is contained in:
parent
5a81908ed4
commit
4f9046af6e
2 changed files with 17 additions and 20 deletions
|
@ -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)
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue