1
0
mirror of https://github.com/moparisthebest/SickRage synced 2024-12-12 11:02:21 -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
# along with SickRage. If not, see <http://www.gnu.org/licenses/>.
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)
logger.log(u"Internal name cache set to: " + str(nameCache), logger.DEBUG)

View File

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

View File

@ -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()