@ -22,12 +22,12 @@ import sickbeard
from . import db
from . import db
from . helpers import try_int
from . helpers import try_int
from _23 import list_items
from six import iteritems
from six import iteritems
# noinspection PyUnreachableCode
# noinspection PyUnreachableCode
if False :
if False :
from typing import AnyStr , Tuple , Union
from typing import AnyStr , Optional , Tuple , Union
from . tv import TVShow , TVShowBase
nameCache = { }
nameCache = { }
nameCacheLock = threading . Lock ( )
nameCacheLock = threading . Lock ( )
@ -47,10 +47,11 @@ def addNameToCache(name, tvid=0, prodid=0, season=-1):
"""
"""
global nameCache
global nameCache
# standardize the name we're using to account for small differences in providers
with nameCacheLock :
name = sickbeard . helpers . full_sanitize_scene_name ( name )
# standardize the name we're using to account for small differences in providers
if name not in nameCache :
name = sickbeard . helpers . full_sanitize_scene_name ( name )
nameCache [ name ] = [ int ( tvid ) , int ( prodid ) , season ]
if name not in nameCache :
nameCache [ name ] = [ int ( tvid ) , int ( prodid ) , season ]
def retrieveNameFromCache ( name ) :
def retrieveNameFromCache ( name ) :
@ -63,16 +64,19 @@ def retrieveNameFromCache(name):
global nameCache
global nameCache
name = sickbeard . helpers . full_sanitize_scene_name ( name )
name = sickbeard . helpers . full_sanitize_scene_name ( name )
if name in nameCache :
try :
return int ( nameCache [ name ] [ 0 ] ) , int ( nameCache [ name ] [ 1 ] )
if name in nameCache :
return int ( nameCache [ name ] [ 0 ] ) , int ( nameCache [ name ] [ 1 ] )
except ( BaseException , Exception ) :
pass
return None , None
return None , None
def buildNameCache ( show_obj = None ) :
def buildNameCache ( show_obj = None ) :
# type: (Optional[Union[TVShow, TVShowBase]]) -> None
""" Adds all new name exceptions to the namecache memory and flushes any removed name exceptions
""" Adds all new name exceptions to the namecache memory and flushes any removed name exceptions
: param show_obj : ( optional ) Only update namecache for this show object
: param show_obj : Only update name cache for this show object , otherwise update all
: type show_obj : sickbeard . tv . TVShow or None
"""
"""
global nameCache
global nameCache
with nameCacheLock :
with nameCacheLock :
@ -80,7 +84,8 @@ def buildNameCache(show_obj=None):
if show_obj :
if show_obj :
# search for only the requested show id and flush old show entries from namecache
# search for only the requested show id and flush old show entries from namecache
show_ids = { show_obj . tvid : [ show_obj . prodid ] }
show_ids = { show_obj . tvid : [ show_obj . prodid ] }
nameCache = dict ( [ ( k , v ) for k , v in list_items ( nameCache ) if v != ( show_obj . tvid , show_obj . prodid ) ] )
nameCache = dict ( [ ( k , v ) for k , v in iteritems ( nameCache )
if not ( v [ 0 ] == show_obj . tvid and v [ 1 ] == show_obj . prodid ) ] )
# add standard indexer name to namecache
# add standard indexer name to namecache
nameCache [ sickbeard . helpers . full_sanitize_scene_name ( show_obj . name ) ] = [ show_obj . tvid , show_obj . prodid , - 1 ]
nameCache [ sickbeard . helpers . full_sanitize_scene_name ( show_obj . name ) ] = [ show_obj . tvid , show_obj . prodid , - 1 ]
@ -123,5 +128,6 @@ def remove_from_namecache(tvid, prodid):
"""
"""
global nameCache
global nameCache
if nameCache :
with nameCacheLock :
nameCache = dict ( [ ( k , v ) for k , v in list_items ( nameCache ) if v != ( tvid , prodid ) ] )
if nameCache :
nameCache = dict ( [ ( k , v ) for k , v in iteritems ( nameCache ) if not ( v [ 0 ] == tvid and v [ 1 ] == prodid ) ] )