From 6b9cbc0a7a5e1bb273f9439181d95fe5f5a3c0b2 Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Sat, 27 Mar 2021 19:49:03 -0700 Subject: [PATCH] Create session_history database indices --- plexpy/__init__.py | 77 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 8 deletions(-) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index fc60e663..f7f25fdc 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -2318,27 +2318,88 @@ def dbcheck(): logger.debug("User 'Local' does not exist. Adding user.") c_db.execute('INSERT INTO users (user_id, username) VALUES (0, "Local")') - # Create table indices + # Create session_history table indices c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_tvmaze_lookup ON tvmaze_lookup (rating_key)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_media_type" ' + 'ON "session_history" ("media_type")' ) c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_themoviedb_lookup ON themoviedb_lookup (rating_key)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_rating_key" ' + 'ON "session_history" ("rating_key")' ) c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_musicbrainz_lookup ON musicbrainz_lookup (rating_key)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_parent_rating_key" ' + 'ON "session_history" ("parent_rating_key")' ) c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_image_hash_lookup ON image_hash_lookup (img_hash)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_grandparent_rating_key" ' + 'ON "session_history" ("grandparent_rating_key")' ) c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_cloudinary_lookup ON cloudinary_lookup (img_hash)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_user" ' + 'ON "session_history" ("user")' ) c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_imgur_lookup ON imgur_lookup (img_hash)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_user_id" ' + 'ON "session_history" ("user_id")' ) c_db.execute( - 'CREATE UNIQUE INDEX IF NOT EXISTS idx_sessions_continued ON sessions_continued (user_id, machine_id, media_type)' + 'CREATE INDEX IF NOT EXISTS "idx_session_history_reference_id" ' + 'ON "session_history" ("reference_id" ASC)' + ) + + # Create session_history_metadata table indices + c_db.execute( + 'CREATE INDEX IF NOT EXISTS "idx_session_history_metadata_rating_key" ' + 'ON "session_history_metadata" ("rating_key")' + ) + c_db.execute( + 'CREATE INDEX IF NOT EXISTS "idx_session_history_metadata_section_id" ' + 'ON "session_history_metadata" ("section_id")' + ) + c_db.execute( + 'CREATE INDEX IF NOT EXISTS "idx_session_history_metadata_guid" ' + 'ON "session_history_metadata" ("guid")' + ) + c_db.execute( + 'CREATE INDEX IF NOT EXISTS "idx_session_history_metadata_live" ' + 'ON "session_history_metadata" ("live")' + ) + + # Create session_history_media_info table indices + c_db.execute( + 'CREATE INDEX IF NOT EXISTS "idx_session_history_media_info_transcode_decision" ' + 'ON "session_history_media_info" ("transcode_decision")' + ) + + # Create lookup table indices + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_tvmaze_lookup" ' + 'ON "tvmaze_lookup" ("rating_key")' + ) + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_themoviedb_lookup" ' + 'ON "themoviedb_lookup" ("rating_key")' + ) + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_musicbrainz_lookup" ' + 'ON "musicbrainz_lookup" ("rating_key")' + ) + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_image_hash_lookup" ' + 'ON "image_hash_lookup" ("img_hash")' + ) + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_cloudinary_lookup" ' + 'ON "cloudinary_lookup" ("img_hash")' + ) + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_imgur_lookup" ' + 'ON "imgur_lookup" ("img_hash")' + ) + c_db.execute( + 'CREATE UNIQUE INDEX IF NOT EXISTS "idx_sessions_continued" ' + 'ON "sessions_continued" ("user_id", "machine_id", "media_type")' ) conn_db.commit()