浏览代码

Add migration

Daniel Supernault 2 年之前
父节点
当前提交
9028c88520

+ 7 - 6
app/Console/Commands/MediaS3GarbageCollector.php

@@ -56,12 +56,13 @@ class MediaS3GarbageCollector extends Command
         $limit = $this->option('limit');
         $limit = $this->option('limit');
         $minId = Media::orderByDesc('id')->where('created_at', '<', now()->subHours(12))->first()->id;
         $minId = Media::orderByDesc('id')->where('created_at', '<', now()->subHours(12))->first()->id;
 
 
-        $gc = Media::whereNotNull(['status_id', 'cdn_url', 'replicated_at'])
-        ->whereNot('version', '4')
-        ->where('id', '<', $minId)
-        ->inRandomOrder()
-        ->take($limit)
-        ->get();
+        $gc = Media::whereRemoteMedia(false)
+            ->whereNotNull(['status_id', 'cdn_url', 'replicated_at'])
+            ->whereNot('version', '4')
+            ->where('id', '<', $minId)
+            ->inRandomOrder()
+            ->take($limit)
+            ->get();
 
 
         $totalSize = 0;
         $totalSize = 0;
         $bar = $this->output->createProgressBar($gc->count());
         $bar = $this->output->createProgressBar($gc->count());

+ 32 - 0
database/migrations/2022_12_18_034556_add_remote_media_index_to_media_table.php

@@ -0,0 +1,32 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::table('media', function (Blueprint $table) {
+            $table->index('remote_media');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::table('media', function (Blueprint $table) {
+            $table->dropIndex('media_remote_media_index');
+        });
+    }
+};