1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-13 11:32:20 -05:00

Added thread lock for internal name cache.

Removed unrequired scene exception retrieval during adding of new shows.
This commit is contained in:
echel0n 2014-07-17 19:37:14 -07:00
parent 70c2a2d130
commit a435a7d3d2
3 changed files with 34 additions and 37 deletions

View File

@ -15,15 +15,13 @@
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with SickRage. If not, see <http://www.gnu.org/licenses/>. # along with SickRage. If not, see <http://www.gnu.org/licenses/>.
import threading
import sickbeard import sickbeard
from sickbeard import db from sickbeard import db
from sickbeard.helpers import sanitizeSceneName
from sickbeard import logger from sickbeard import logger
nameCache = None nameCache = None
nameCacheLock = threading.Lock()
def addNameToCache(name, indexer_id=0): def addNameToCache(name, indexer_id=0):
""" """
@ -98,45 +96,46 @@ def buildNameCache(show=None):
if not nameCache: if not nameCache:
nameCache = {} nameCache = {}
# clear internal name cache with nameCacheLock:
clearCache() # clear internal name cache
clearCache()
# update scene exception names # update scene exception names
sickbeard.scene_exceptions.retrieve_exceptions() sickbeard.scene_exceptions.retrieve_exceptions()
if not show: if not show:
logger.log(u"Building internal name cache for all shows", logger.MESSAGE) logger.log(u"Building internal name cache for all shows", logger.MESSAGE)
cacheDB = db.DBConnection('cache.db') cacheDB = db.DBConnection('cache.db')
cache_results = cacheDB.select("SELECT * FROM scene_names") cache_results = cacheDB.select("SELECT * FROM scene_names")
for cache_result in cache_results: for cache_result in cache_results:
name = sickbeard.helpers.full_sanitizeSceneName(cache_result["name"]) name = sickbeard.helpers.full_sanitizeSceneName(cache_result["name"])
if name in nameCache: if name in nameCache:
continue continue
indexer_id = int(cache_result["indexer_id"]) indexer_id = int(cache_result["indexer_id"])
nameCache[name] = 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 curSeason in [-1] + sickbeard.scene_exceptions.get_scene_seasons(show.indexerid):
for name in list(set( for name in list(set(sickbeard.scene_exceptions.get_scene_exceptions(show.indexerid, season=curSeason) + [
sickbeard.scene_exceptions.get_scene_exceptions(show.indexerid, season=curSeason) + [ show.name])):
show.name])):
name = sickbeard.helpers.full_sanitizeSceneName(name) name = sickbeard.helpers.full_sanitizeSceneName(name)
if name in nameCache: if name in nameCache:
continue continue
nameCache[name] = int(show.indexerid) 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): logger.log(u"Internal name cache set to: " + str(nameCache), logger.DEBUG)
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)

View File

@ -34,6 +34,7 @@ xem_exception_dict = {}
exceptionsCache = {} exceptionsCache = {}
exceptionsSeasonCache = {} exceptionsSeasonCache = {}
exceptionLock = threading.Lock()
def shouldRefresh(list): def shouldRefresh(list):
MAX_REFRESH_AGE_SECS = 86400 # 1 day MAX_REFRESH_AGE_SECS = 86400 # 1 day

View File

@ -354,9 +354,6 @@ class QueueItemAdd(ShowQueueItem):
logger.ERROR) logger.ERROR)
logger.log(traceback.format_exc(), logger.DEBUG) logger.log(traceback.format_exc(), logger.DEBUG)
# before we parse local files lets update exceptions
sickbeard.scene_exceptions.retrieve_exceptions()
# update internal name cache # update internal name cache
name_cache.buildNameCache() name_cache.buildNameCache()