From b669b379c07ba28c8ea8abdff058b77786e1b350 Mon Sep 17 00:00:00 2001 From: g0ldyy <153996346+g0ldyy@users.noreply.github.com> Date: Mon, 5 Jan 2026 18:57:56 +0100 Subject: [PATCH] perf: add `idx_torrents_info_hash` for improved lookup performance --- comet/core/database.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/comet/core/database.py b/comet/core/database.py index 7d6144b..1417a8c 100644 --- a/comet/core/database.py +++ b/comet/core/database.py @@ -386,6 +386,15 @@ async def setup_database(): """ ) + # Optimization for lookups by info_hash only + # Covers: SELECT sources, media_id FROM torrents WHERE info_hash = $1 + await database.execute( + """ + CREATE INDEX IF NOT EXISTS idx_torrents_info_hash + ON torrents (info_hash) + """ + ) + # ============================================================================= # DEBRID_AVAILABILITY TABLE INDEXES # ============================================================================= @@ -689,7 +698,6 @@ async def _migrate_indexes(): "torrents_episode_only_idx", "torrents_no_season_episode_idx", "idx_torrents_media_cache_lookup", - "idx_torrents_info_hash", "idx_torrents_tracker_analytics", "idx_torrents_size_filter", "idx_torrents_seeders_desc",