diff --git a/app/Console/Commands/CatchUnoptimizedMedia.php b/app/Console/Commands/CatchUnoptimizedMedia.php index 9038c12fb..a62bd8651 100644 --- a/app/Console/Commands/CatchUnoptimizedMedia.php +++ b/app/Console/Commands/CatchUnoptimizedMedia.php @@ -40,22 +40,20 @@ class CatchUnoptimizedMedia extends Command */ public function handle() { - DB::transaction(function() { - Media::whereNull('processed_at') - ->where('skip_optimize', '!=', true) - ->whereNull('remote_url') - ->whereNotNull('status_id') - ->whereNotNull('media_path') - ->where('created_at', '>', now()->subHours(1)) - ->whereIn('mime', [ - 'image/jpeg', - 'image/png', - ]) - ->chunk(50, function($medias) { - foreach ($medias as $media) { - ImageOptimize::dispatch($media); - } - }); - }); + Media::whereNull('processed_at') + ->where('created_at', '>', now()->subHours(1)) + ->where('skip_optimize', '!=', true) + ->whereNull('remote_url') + ->whereNotNull('status_id') + ->whereNotNull('media_path') + ->whereIn('mime', [ + 'image/jpeg', + 'image/png', + ]) + ->chunk(50, function($medias) { + foreach ($medias as $media) { + ImageOptimize::dispatch($media); + } + }); } } diff --git a/app/Console/Commands/MediaGarbageCollector.php b/app/Console/Commands/MediaGarbageCollector.php index c8fce9199..3c266a0d6 100644 --- a/app/Console/Commands/MediaGarbageCollector.php +++ b/app/Console/Commands/MediaGarbageCollector.php @@ -4,7 +4,6 @@ namespace App\Console\Commands; use Illuminate\Console\Command; use App\{Media, Status}; -use Carbon\Carbon; use App\Services\MediaStorageService; class MediaGarbageCollector extends Command @@ -40,11 +39,10 @@ class MediaGarbageCollector extends Command */ public function handle() { - $limit = 20000; + $limit = 500; $gc = Media::whereNull('status_id') - ->where('created_at', '<', Carbon::now()->subHours(12)->toDateTimeString()) - ->orderBy('created_at','asc') + ->where('created_at', '<', now()->subHours(2)->toDateTimeString()) ->take($limit) ->get(); diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index dd1bae944..cada75351 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -25,8 +25,8 @@ class Kernel extends ConsoleKernel */ protected function schedule(Schedule $schedule) { - $schedule->command('media:optimize')->hourly(); - $schedule->command('media:gc')->hourly(); + $schedule->command('media:optimize')->hourlyAt(40); + $schedule->command('media:gc')->hourlyAt(5); $schedule->command('horizon:snapshot')->everyFiveMinutes(); $schedule->command('story:gc')->everyFiveMinutes(); $schedule->command('gc:failedjobs')->dailyAt(3); diff --git a/config/logging.php b/config/logging.php index 34034449e..ae21f72ac 100644 --- a/config/logging.php +++ b/config/logging.php @@ -89,6 +89,12 @@ return [ 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], + + 'media' => [ + 'driver' => 'single', + 'path' => storage_path('logs/media.log'), + 'level' => 'debug' + ], ], ]; diff --git a/config/media.php b/config/media.php index bd392998a..c73b26798 100644 --- a/config/media.php +++ b/config/media.php @@ -1,6 +1,8 @@ env('MEDIA_DELETE_LOCAL_AFTER_CLOUD', true), + 'exif' => [ 'database' => env('MEDIA_EXIF_DATABASE', false), ],