Fixed duplicate tv cache issue.

This commit is contained in:
echel0n 2014-06-27 20:33:31 -07:00
parent c3e2ff5193
commit cfbb7678a9

View file

@ -55,8 +55,14 @@ class CacheDBConnection(db.DBConnection):
self.action( self.action(
"CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT)") "CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT)")
else: else:
# remove duplicates sqlResults = self.select(
self.action("DELETE FROM " + providerName + " WHERE url NOT IN (SELECT url FROM " + providerName + " GROUP BY url)") "SELECT url, COUNT(url) as count FROM [" + providerName + "] GROUP BY url HAVING count > 1")
for cur_dupe in sqlResults:
self.action("DELETE FROM [" + providerName + "] WHERE url = ?", [cur_dupe["url"]])
# add unique index to prevent further dupes from happening if one does not exist
self.action("CREATE UNIQUE INDEX IF NOT EXISTS idx_url ON " + providerName + " (url)")
except Exception, e: except Exception, e:
if str(e) != "table [" + providerName + "] already exists": if str(e) != "table [" + providerName + "] already exists":
raise raise
@ -69,13 +75,6 @@ class CacheDBConnection(db.DBConnection):
if str(e) != "table lastUpdate already exists": if str(e) != "table lastUpdate already exists":
raise raise
# Create unique index for provider table to prevent duplicate entries
try:
self.action("CREATE UNIQUE INDEX IF NOT EXISTS idx_url ON " + providerName + " (url)")
except Exception, e:
raise
class TVCache(): class TVCache():
def __init__(self, provider): def __init__(self, provider):