From 4da248ef9b0c7a4ccc72fb9fb65d7f02575c7e46 Mon Sep 17 00:00:00 2001 From: echel0n Date: Mon, 26 May 2014 14:06:54 -0700 Subject: [PATCH] Fixed internal indexer scene name cache which resolved issues with searching and snatching. --- sickbeard/helpers.py | 19 ++++++------------- sickbeard/scene_exceptions.py | 24 +++++++++++++++++++----- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/sickbeard/helpers.py b/sickbeard/helpers.py index fd6e690f..953916ce 100644 --- a/sickbeard/helpers.py +++ b/sickbeard/helpers.py @@ -1014,21 +1014,14 @@ def get_show_by_name(name, useIndexer=False): showObj = sickbeard.name_cache.retrieveShowFromCache(name) if showObj: return showObj - if not showObj and sickbeard.showList: - showNames = list(set(sickbeard.show_name_helpers.sceneToNormalShowNames(name))) - for showName in showNames: - if showName in sickbeard.scene_exceptions.exceptionIndexerCache: - showObj = findCertainShow(sickbeard.showList, int(sickbeard.scene_exceptions.exceptionIndexerCache[showName])) - if showObj: - break + if name in sickbeard.scene_exceptions.exceptionIndexerCache: + showObj = findCertainShow(sickbeard.showList, int(sickbeard.scene_exceptions.exceptionIndexerCache[name])) - if useIndexer and not showObj: - (sn, idx, id) = searchIndexerForShowID(showName, ui=classes.ShowListUI) - if id: - showObj = findCertainShow(sickbeard.showList, int(id)) - if showObj: - break + if useIndexer and not showObj: + (sn, idx, id) = searchIndexerForShowID(name, ui=classes.ShowListUI) + if id: + showObj = findCertainShow(sickbeard.showList, int(id)) # add show to cache if showObj: diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index 9203c496..6f11252e 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -125,12 +125,11 @@ def retrieve_exceptions(): scene_exceptions table in cache.db. Also clears the scene name cache. """ - global exceptionCache, exceptionSeasonCache, exceptionIndexerCache + global exceptionCache, exceptionSeasonCache exception_dict = {} exceptionCache = {} exceptionSeasonCache = {} - exceptionIndexerCache = {} # exceptions are stored on github pages for indexer in sickbeard.indexerApi().indexers: @@ -192,9 +191,6 @@ def retrieve_exceptions(): for cur_exception_dict in exception_dict[cur_indexer_id]: cur_exception, curSeason = cur_exception_dict.items()[0] - # updating internal scene cache - exceptionIndexerCache[helpers.full_sanitizeSceneName(cur_exception)] = cur_indexer_id - # if this exception isn't already in the DB then add it if cur_exception not in existing_exceptions: myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season) VALUES (?,?,?)", @@ -208,6 +204,9 @@ def retrieve_exceptions(): else: logger.log(u"No scene exceptions update needed") + # build indexer scene name cache + buildIndexerCache() + def update_scene_exceptions(indexer_id, scene_exceptions): """ Given a indexer_id, and a list of all show scene exceptions, update the db. @@ -267,3 +266,18 @@ def getSceneSeasons(indexer_id): myDB = db.DBConnection("cache.db") seasons = myDB.select("SELECT DISTINCT season FROM scene_exceptions WHERE indexer_id = ?", [indexer_id]) return [cur_exception["season"] for cur_exception in seasons] + +def buildIndexerCache(): + logger.log(u"Updating internal scene name cache", logger.MESSAGE) + global exceptionIndexerCache + exceptionIndexerCache = {} + + for show in sickbeard.showList: + for curSeason in [-1] + sickbeard.scene_exceptions.get_scene_seasons(show.indexerid): + exceptionIndexerCache[helpers.full_sanitizeSceneName(show.name)] = show.indexerid + for name in get_scene_exceptions(show.indexerid, season=curSeason): + exceptionIndexerCache[name] = show.indexerid + exceptionIndexerCache[helpers.full_sanitizeSceneName(name)] = show.indexerid + + logger.log(u"Updated internal scene name cache", logger.MESSAGE) + logger.log(u"Internal scene name cache set to: " + str(exceptionIndexerCache), logger.DEBUG) \ No newline at end of file