diff --git a/sickbeard/name_cache.py b/sickbeard/name_cache.py index 05e4b3ec..06bd82a5 100644 --- a/sickbeard/name_cache.py +++ b/sickbeard/name_cache.py @@ -15,15 +15,13 @@ # # You should have received a copy of the GNU General Public License # along with SickRage. If not, see . - +import threading import sickbeard - from sickbeard import db -from sickbeard.helpers import sanitizeSceneName from sickbeard import logger nameCache = None - +nameCacheLock = threading.Lock() def addNameToCache(name, indexer_id=0): """ @@ -98,45 +96,46 @@ def buildNameCache(show=None): if not nameCache: nameCache = {} - # clear internal name cache - clearCache() + with nameCacheLock: + # clear internal name cache + clearCache() - # update scene exception names - sickbeard.scene_exceptions.retrieve_exceptions() + # update scene exception names + sickbeard.scene_exceptions.retrieve_exceptions() - if not show: - logger.log(u"Building internal name cache for all shows", logger.MESSAGE) + if not show: + logger.log(u"Building internal name cache for all shows", logger.MESSAGE) - cacheDB = db.DBConnection('cache.db') - cache_results = cacheDB.select("SELECT * FROM scene_names") - for cache_result in cache_results: - name = sickbeard.helpers.full_sanitizeSceneName(cache_result["name"]) - if name in nameCache: - continue + cacheDB = db.DBConnection('cache.db') + cache_results = cacheDB.select("SELECT * FROM scene_names") + for cache_result in cache_results: + name = sickbeard.helpers.full_sanitizeSceneName(cache_result["name"]) + if name in nameCache: + continue - indexer_id = int(cache_result["indexer_id"]) - nameCache[name] = indexer_id + indexer_id = int(cache_result["indexer_id"]) + nameCache[name] = indexer_id + + for show in sickbeard.showList: + for curSeason in [-1] + sickbeard.scene_exceptions.get_scene_seasons(show.indexerid): + for name in list(set( + sickbeard.scene_exceptions.get_scene_exceptions(show.indexerid, season=curSeason) + [ + show.name])): + name = sickbeard.helpers.full_sanitizeSceneName(name) + if name in nameCache: + continue + + nameCache[name] = int(show.indexerid) + else: + logger.log(u"Building internal name cache for " + show.name, logger.MESSAGE) - for show in sickbeard.showList: for curSeason in [-1] + sickbeard.scene_exceptions.get_scene_seasons(show.indexerid): - for name in list(set( - sickbeard.scene_exceptions.get_scene_exceptions(show.indexerid, season=curSeason) + [ - show.name])): + for name in list(set(sickbeard.scene_exceptions.get_scene_exceptions(show.indexerid, season=curSeason) + [ + show.name])): name = sickbeard.helpers.full_sanitizeSceneName(name) if name in nameCache: continue nameCache[name] = int(show.indexerid) - else: - logger.log(u"Building internal name cache for " + show.name, logger.MESSAGE) - for curSeason in [-1] + sickbeard.scene_exceptions.get_scene_seasons(show.indexerid): - for name in list(set(sickbeard.scene_exceptions.get_scene_exceptions(show.indexerid, season=curSeason) + [ - show.name])): - name = sickbeard.helpers.full_sanitizeSceneName(name) - if name in nameCache: - continue - - nameCache[name] = int(show.indexerid) - - logger.log(u"Internal name cache set to: " + str(nameCache), logger.DEBUG) \ No newline at end of file + logger.log(u"Internal name cache set to: " + str(nameCache), logger.DEBUG) \ No newline at end of file diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index f9b5924a..7ec98df4 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -34,6 +34,7 @@ xem_exception_dict = {} exceptionsCache = {} exceptionsSeasonCache = {} +exceptionLock = threading.Lock() def shouldRefresh(list): MAX_REFRESH_AGE_SECS = 86400 # 1 day diff --git a/sickbeard/show_queue.py b/sickbeard/show_queue.py index 1df0462a..f1641c2f 100644 --- a/sickbeard/show_queue.py +++ b/sickbeard/show_queue.py @@ -354,9 +354,6 @@ class QueueItemAdd(ShowQueueItem): logger.ERROR) logger.log(traceback.format_exc(), logger.DEBUG) - # before we parse local files lets update exceptions - sickbeard.scene_exceptions.retrieve_exceptions() - # update internal name cache name_cache.buildNameCache()