mirror of https://github.com/pixelfed/pixelfed.git
Update MediaGarbageCollector
This commit is contained in:
parent
20710f4d6e
commit
758a828fdf
|
@ -5,6 +5,7 @@ namespace App\Console\Commands;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
use App\{Media, Status};
|
use App\{Media, Status};
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
|
use App\Services\MediaStorageService;
|
||||||
|
|
||||||
class MediaGarbageCollector extends Command
|
class MediaGarbageCollector extends Command
|
||||||
{
|
{
|
||||||
|
@ -41,8 +42,8 @@ class MediaGarbageCollector extends Command
|
||||||
{
|
{
|
||||||
$limit = 20000;
|
$limit = 20000;
|
||||||
|
|
||||||
$gc = Media::doesntHave('status')
|
$gc = Media::whereNull('status_id')
|
||||||
->where('created_at', '<', Carbon::now()->subHours(1)->toDateTimeString())
|
->where('created_at', '<', Carbon::now()->subHours(12)->toDateTimeString())
|
||||||
->orderBy('created_at','asc')
|
->orderBy('created_at','asc')
|
||||||
->take($limit)
|
->take($limit)
|
||||||
->get();
|
->get();
|
||||||
|
@ -50,14 +51,7 @@ class MediaGarbageCollector extends Command
|
||||||
$bar = $this->output->createProgressBar($gc->count());
|
$bar = $this->output->createProgressBar($gc->count());
|
||||||
$bar->start();
|
$bar->start();
|
||||||
foreach($gc as $media) {
|
foreach($gc as $media) {
|
||||||
$path = storage_path("app/$media->media_path");
|
MediaStorageService::delete($media);
|
||||||
$thumb = storage_path("app/$media->thumbnail_path");
|
|
||||||
if(is_file($path)) {
|
|
||||||
unlink($path);
|
|
||||||
}
|
|
||||||
if(is_file($thumb)) {
|
|
||||||
unlink($thumb);
|
|
||||||
}
|
|
||||||
$media->forceDelete();
|
$media->forceDelete();
|
||||||
$bar->advance();
|
$bar->advance();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue