From 3b34151c3c0ae2fb0b88915d72be704f8ab56b08 Mon Sep 17 00:00:00 2001 From: Roardom Date: Sat, 31 Aug 2024 10:43:40 +0000 Subject: [PATCH] update: add indexes to torrents table Index on the name makes it so that the query to check if a torrent of the same name already exists upons upload is instant instead of taking 600 ms. Index on user_id, status, anon, deleted_at makes home page load instantly instead of taking 10+ seconds to calculate user stats. --- ...2_082323_add_indexes_to_torrents_table.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 database/migrations/2024_07_02_082323_add_indexes_to_torrents_table.php diff --git a/database/migrations/2024_07_02_082323_add_indexes_to_torrents_table.php b/database/migrations/2024_07_02_082323_add_indexes_to_torrents_table.php new file mode 100644 index 0000000000..202c3b1fd0 --- /dev/null +++ b/database/migrations/2024_07_02_082323_add_indexes_to_torrents_table.php @@ -0,0 +1,32 @@ + + * @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0 + */ + +use Illuminate\Database\Migrations\Migration; +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Support\Facades\Schema; + +return new class () extends Migration { + /** + * Run the migrations. + */ + public function up(): void + { + Schema::table('torrents', function (Blueprint $table): void { + $table->index(['user_id', 'status', 'anon', 'deleted_at']); + $table->index('name'); + }); + } +};