Fixes issues with scene exception updating when editing a show, should resolve problems with it duplicating scene exception name over and over again.

Reduced DB sleep timer to increase overall performance of application.

Improved generic queue code for threading.
This commit is contained in:
echel0n 2014-07-19 22:26:28 -07:00
parent bd20f9d2ae
commit 636bbfa2de
6 changed files with 29 additions and 32 deletions

View file

@ -164,7 +164,7 @@ class DBConnection(object):
logger.log(u"Fatal error executing query: " + ex(e), logger.ERROR)
raise
time.sleep(0.05)
time.sleep(0.02)
return sqlResult
@ -201,7 +201,7 @@ class DBConnection(object):
logger.log(u"Fatal error executing query: " + ex(e), logger.ERROR)
raise
time.sleep(0.05)
time.sleep(0.02)
return sqlResult

View file

@ -31,7 +31,6 @@ class QueuePriorities:
class GenericQueue(object):
def __init__(self):
self.queueItem = None
self.currentItem = None
self.queue = []
@ -59,7 +58,7 @@ class GenericQueue(object):
def run(self, force=False):
# only start a new task if one isn't already going
if self.queueItem is None or not self.queueItem.isAlive():
if self.currentItem is None or not self.currentItem.isAlive():
# if the thread is dead then the current item should be finished
if self.currentItem:
@ -85,19 +84,13 @@ class GenericQueue(object):
return y.priority - x.priority
self.queue.sort(cmp=sorter)
queueItem = self.queue.pop(0)
if queueItem.priority < self.min_priority:
if self.queue[0].priority < self.min_priority:
return
# launch the queue item in a thread
queueItem.name = self.queue_name + '-' + queueItem.name
queueItem.start()
self.currentItem = queueItem
queueItem.join()
self.currentItem = self.queue.pop(0)
self.currentItem.name = self.queue_name + '-' + self.currentItem.name
self.currentItem.start()
class QueueItem(threading.Thread):
def __init__(self, name, action_id=0):
@ -107,8 +100,8 @@ class QueueItem(threading.Thread):
self.inProgress = False
self.priority = QueuePriorities.NORMAL
self.action_id = action_id
self.added = None
self.stop = threading.Event()
self.added = None
def run(self):
"""Implementing classes should call this"""

View file

@ -104,14 +104,14 @@ class NameParser(object):
matches = []
bestResult = None
doneSearch = False
for regexMode in self.regexModes:
if doneSearch:
break
self._compile_regexes(regexMode)
for (cur_regexMode, cur_regex_name, cur_regex) in self.compiled_regexes:
time.sleep(0.02)
match = cur_regex.match(name)
if not match:
@ -140,6 +140,7 @@ class NameParser(object):
if result.show:
# confirm passed in show object indexer id matches result show object indexer id
if self.showObj and self.showObj.indexerid != result.show.indexerid:
doneSearch = True
break
# confirm we are using correct regex mode
@ -255,6 +256,9 @@ class NameParser(object):
bestResult.episode_numbers = new_episode_numbers
bestResult.season_number = new_season_numbers[0]
# CPU sleep
time.sleep(0.02)
return bestResult
def _combine_results(self, first, second, attr):

View file

@ -410,16 +410,15 @@ class PostProcessor(object):
if len(sql_results) == 0:
continue
show = helpers.findCertainShow(sickbeard.showList, int(sql_results[0]["showid"]))
if not show:
continue
indexer_id = int(sql_results[0]["showid"])
season = int(sql_results[0]["season"])
quality = int(sql_results[0]["quality"])
if quality == common.Quality.UNKNOWN:
quality = None
show = helpers.findCertainShow(sickbeard.showList, indexer_id)
self.in_history = True
to_return = (show, season, [], quality)
self._log("Found result in history: " + str(to_return), logger.DEBUG)
@ -599,7 +598,9 @@ class PostProcessor(object):
logger.log(u"Unable to parse, skipping: " + ex(e), logger.DEBUG)
continue
if cur_show:
if not cur_show:
continue
else:
show = cur_show
if cur_quality and not (self.in_history and quality):

View file

@ -259,17 +259,16 @@ def update_scene_exceptions(indexer_id, scene_exceptions):
"""
myDB = db.DBConnection('cache.db')
myDB.action('DELETE FROM scene_exceptions WHERE indexer_id=? and custom=1', [indexer_id])
myDB.action('DELETE FROM scene_exceptions WHERE indexer_id=?', [indexer_id])
logger.log(u"Updating scene exceptions", logger.MESSAGE)
for cur_season in [-1] + get_scene_seasons(indexer_id):
for cur_exception in scene_exceptions:
for cur_exception in scene_exceptions:
if not isinstance(cur_exception, unicode):
cur_exception = unicode(cur_exception, 'utf-8', 'replace')
if not isinstance(cur_exception, unicode):
cur_exception = unicode(cur_exception, 'utf-8', 'replace')
myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season, custom) VALUES (?,?,?,?)",
[indexer_id, cur_exception, cur_season, 1])
myDB.action("INSERT INTO scene_exceptions (indexer_id, show_name, season) VALUES (?,?,?)",
[indexer_id, cur_exception, -1])
def _anidb_exceptions_fetcher():
global anidb_exception_dict

View file

@ -427,14 +427,14 @@ def searchProviders(show, season, episodes, manualSearch=False):
logger.log(u"" + str(show.name) + " is not an anime skiping ...")
continue
foundResults.setdefault(provider.name, {})
foundResults[provider.name] = {}
searchCount = 0
search_mode = 'eponly'
if seasonSearch and provider.search_mode == 'sponly':
search_mode = provider.search_mode
while (True):
while(True):
searchCount += 1
if search_mode == 'sponly':