From c0453eae47bd0b85d666fd8733f5d1f7a40daabe Mon Sep 17 00:00:00 2001 From: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com> Date: Mon, 2 Nov 2020 19:49:33 -0800 Subject: [PATCH] Fix unique img_hash in database --- plexpy/__init__.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plexpy/__init__.py b/plexpy/__init__.py index a191ffc3..61c88eb6 100644 --- a/plexpy/__init__.py +++ b/plexpy/__init__.py @@ -784,7 +784,7 @@ def dbcheck(): # image_hash_lookup table :: This table keeps record of the image hash lookups c_db.execute( 'CREATE TABLE IF NOT EXISTS image_hash_lookup (id INTEGER PRIMARY KEY AUTOINCREMENT, ' - 'img_hash TEXT, img TEXT, rating_key INTEGER, width INTEGER, height INTEGER, ' + 'img_hash TEXT UNIQUE, img TEXT, rating_key INTEGER, width INTEGER, height INTEGER, ' 'opacity INTEGER, background TEXT, blur INTEGER, fallback TEXT)' ) @@ -2210,6 +2210,13 @@ def dbcheck(): 'ALTER TABLE exports ADD COLUMN total_items INTEGER DEFAULT 0' ) + # Upgrade image_hash_lookup table from earlier versions + try: + c_db.execute('DELETE FROM image_hash_lookup ' + 'WHERE id NOT IN (SELECT MIN(id) FROM image_hash_lookup GROUP BY img_hash)') + except sqlite3.OperationalError: + pass + # Add "Local" user to database as default unauthenticated user. result = c_db.execute('SELECT id FROM users WHERE username = "Local"') if not result.fetchone():