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(
"CREATE TABLE [" + providerName + "] (name TEXT, season NUMERIC, episodes TEXT, indexerid NUMERIC, url TEXT, time NUMERIC, quality TEXT)")
else:
# remove duplicates
self.action("DELETE FROM " + providerName + " WHERE url NOT IN (SELECT url FROM " + providerName + " GROUP BY url)")
sqlResults = self.select(
"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:
if str(e) != "table [" + providerName + "] already exists":
raise
@ -69,13 +75,6 @@ class CacheDBConnection(db.DBConnection):
if str(e) != "table lastUpdate already exists":
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():
def __init__(self, provider):