Commit dc9bad3a authored by Dustyn Gibson's avatar Dustyn Gibson
Browse files

Name cache cleanup

parent a7fa4c19
......@@ -55,7 +55,7 @@ def retrieveNameFromCache(name):
if name in nameCache:
return int(nameCache[name])
def clearCache():
def clearCache(indexerid=0):
"""
Deletes all "unknown" entries from the cache (names with indexer_id of 0).
"""
......@@ -66,9 +66,9 @@ def clearCache():
nameCache = {}
cacheDB = db.DBConnection('cache.db')
cacheDB.action("DELETE FROM scene_names WHERE indexer_id = ?", [0])
cacheDB.action("DELETE FROM scene_names WHERE indexer_id = ? OR indexer_id = ?", (indexerid, 0))
toRemove = [key for key, value in nameCache.iteritems() if value == 0]
toRemove = [key for key, value in nameCache.iteritems() if value == 0 or value == indexerid]
for key in toRemove:
del nameCache[key]
......@@ -83,39 +83,16 @@ def saveNameCacheToDb():
def buildNameCache(show=None):
global nameCache
with nameCacheLock:
# clear internal name cache
clearCache()
# update scene exception names
sickbeard.scene_exceptions.retrieve_exceptions()
if not show:
logger.log(u"Building internal name cache for all shows", logger.INFO)
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
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.INFO)
sickbeard.scene_exceptions.retrieve_exceptions()
if not show:
logger.log(u"Building internal name cache for all shows", logger.INFO)
for show in sickbeard.showList:
buildNameCache(show)
else:
with nameCacheLock:
logger.log(u"Building internal name cache for " + show.name, logger.INFO)
clearCache(show.indexerid)
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])):
......@@ -124,5 +101,4 @@ def buildNameCache(show=None):
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 for " + show.name + " set to: [ " + u', '.join([key for key, value in nameCache.iteritems() if value == show.indexerid]) +" ]" , logger.DEBUG)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment