diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index e0cb730a..b4bbbf84 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1078,9 +1078,9 @@ def get_show_by_name(name, useIndexer=False): if showObj: return showObj if not showObj and sickbeard.showList: - if name in sickbeard.scene_exceptions.exceptionIndexerCache: - showObj = findCertainShow(sickbeard.showList, - int(sickbeard.scene_exceptions.exceptionIndexerCache[name])) + scene_indexerid, scene_season = sickbeard.scene_exceptions.get_scene_exception_by_name(name) + if scene_indexerid: + showObj = findCertainShow(sickbeard.showList, scene_indexerid) if useIndexer and not showObj: (sn, idx, id) = searchIndexerForShowID(name, ui=classes.ShowListUI) diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index e6fdaeb9..13c34a09 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -26,11 +26,6 @@ from sickbeard import name_cache from sickbeard import logger from sickbeard import db -exception_dict = None -exceptionCache = None -exceptionSeasonCache = None -exceptionIndexerCache = None - def shouldRefresh(list): MAX_REFRESH_AGE_SECS = 86400 # 1 day @@ -54,37 +49,30 @@ def get_scene_exceptions(indexer_id, season=-1): Given a indexer_id, return a list of all the scene exceptions. """ - global exceptionCache + exceptionsList = {} - if indexer_id not in exceptionCache or season not in exceptionCache[indexer_id]: - myDB = db.DBConnection('cache.db') - exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE indexer_id = ? and season = ?", - [indexer_id, season]) + myDB = db.DBConnection('cache.db') + exceptions = myDB.select("SELECT show_name FROM scene_exceptions WHERE indexer_id = ? and season = ?", + [indexer_id, season]) + if exceptions: exceptionsList = list(set([cur_exception["show_name"] for cur_exception in exceptions])) - - if len(exceptionsList): - try: - exceptionCache[indexer_id][season] = exceptionsList - except: - exceptionCache[indexer_id] = {season: exceptionsList} - else: - exceptionsList = list(set(exceptionCache[indexer_id][season])) - - if season == 1: # if we where looking for season 1 we can add generic names - exceptionsList += get_scene_exceptions(indexer_id, season=-1) + if season == 1: # if we where looking for season 1 we can add generic names + exceptionsList += get_scene_exceptions(indexer_id, season=-1) return exceptionsList def get_all_scene_exceptions(indexer_id): + exceptionsList = {} + myDB = db.DBConnection('cache.db') exceptions = myDB.select("SELECT show_name,season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id]) - exceptionsList = {} - [cur_exception["show_name"] for cur_exception in exceptions] - for cur_exception in exceptions: - if not cur_exception["season"] in exceptionsList: - exceptionsList[cur_exception["season"]] = [] - exceptionsList[cur_exception["season"]].append(cur_exception["show_name"]) + + if exceptions: + for cur_exception in exceptions: + if not cur_exception["season"] in exceptionsList: + exceptionsList[cur_exception["season"]] = [] + exceptionsList[cur_exception["season"]].append(cur_exception["show_name"]) return exceptionsList @@ -93,21 +81,18 @@ def get_scene_seasons(indexer_id): """ return a list of season numbers that have scene exceptions """ - global exceptionSeasonCache - - if indexer_id not in exceptionSeasonCache: - myDB = db.DBConnection('cache.db') - sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM scene_exceptions WHERE indexer_id = ?", - [indexer_id]) - exceptionSeasonCache[indexer_id] = [int(x["season"]) for x in sqlResults] - return exceptionSeasonCache[indexer_id] + myDB = db.DBConnection('cache.db') + sqlResults = myDB.select("SELECT DISTINCT(season) as season FROM scene_exceptions WHERE indexer_id = ?", + [indexer_id]) + + if sqlResults: + return [int(x["season"]) for x in sqlResults] def get_scene_exception_by_name(show_name): return get_scene_exception_by_name_multiple(show_name)[0] - def get_scene_exception_by_name_multiple(show_name): """ Given a show name, return the indexerid of the exception, None if no exception @@ -148,12 +133,7 @@ def retrieve_exceptions(): scene_exceptions table in cache.db. Also clears the scene name cache. """ - global exception_dict, exceptionCache, exceptionSeasonCache, exceptionIndexerCache - exception_dict = {} - exceptionCache = {} - exceptionSeasonCache = {} - exceptionIndexerCache = {} # exceptions are stored on github pages if setLastRefresh('normal'): @@ -185,11 +165,10 @@ def retrieve_exceptions(): # regex out the list of shows, taking \' into account # alias_list = [re.sub(r'\\(.)', r'\1', x) for x in re.findall(r"'(.*?)(?