From e624837059da6acb452571c21877789a7ce18eff Mon Sep 17 00:00:00 2001 From: "Bora M. Alper" Date: Fri, 16 Jun 2017 12:08:30 +0300 Subject: [PATCH] create indices in magneticow rather than magneticod (rationale below) It's better to create indices in magneticow rather than magneticod, because magneticod does NOT need them, but magneticow does. --- magneticod/magneticod/persistence.py | 2 -- magneticow/magneticow/magneticow.py | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/magneticod/magneticod/persistence.py b/magneticod/magneticod/persistence.py index 25fe374..27eece4 100644 --- a/magneticod/magneticod/persistence.py +++ b/magneticod/magneticod/persistence.py @@ -50,14 +50,12 @@ class Database: "total_size INTEGER NOT NULL CHECK(total_size > 0)," "discovered_on INTEGER NOT NULL CHECK(discovered_on > 0)" ");") - db_conn.execute("CREATE INDEX IF NOT EXISTS info_hash_index ON torrents (info_hash);") db_conn.execute("CREATE TABLE IF NOT EXISTS files (" "id INTEGER PRIMARY KEY," "torrent_id INTEGER REFERENCES torrents ON DELETE CASCADE ON UPDATE RESTRICT," "size INTEGER NOT NULL," "path TEXT NOT NULL" ");") - db_conn.execute("CREATE INDEX IF NOT EXISTS file_info_hash_index ON files (torrent_id);") return db_conn diff --git a/magneticow/magneticow/magneticow.py b/magneticow/magneticow/magneticow.py index 68b8f46..b39c20f 100644 --- a/magneticow/magneticow/magneticow.py +++ b/magneticow/magneticow/magneticow.py @@ -322,6 +322,8 @@ def initialize_magneticod_db() -> None: magneticod_db.execute("PRAGMA journal_mode=WAL;") magneticod_db.execute("CREATE INDEX IF NOT EXISTS discovered_on_index ON torrents (discovered_on);") + magneticod_db.execute("CREATE INDEX IF NOT EXISTS info_hash_index ON torrents (info_hash);") + magneticod_db.execute("CREATE INDEX IF NOT EXISTS file_info_hash_index ON files (torrent_id);") magneticod_db.execute("CREATE VIRTUAL TABLE temp.fts_torrents USING fts4(name);") magneticod_db.execute("INSERT INTO fts_torrents (docid, name) SELECT id, name FROM torrents;")