From 636bbfa2de373e16235e9cf81a22888dd216c449 Mon Sep 17 00:00:00 2001 From: echel0n Date: Sat, 19 Jul 2014 22:26:28 -0700 Subject: [PATCH] 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. --- sickbeard/db.py | 4 ++-- sickbeard/generic_queue.py | 19 ++++++------------- sickbeard/name_parser/parser.py | 10 +++++++--- sickbeard/postProcessor.py | 11 ++++++----- sickbeard/scene_exceptions.py | 13 ++++++------- sickbeard/search.py | 4 ++-- 6 files changed, 29 insertions(+), 32 deletions(-) diff --git a/sickbeard/db.py b/sickbeard/db.py index e2ebfb57..92d2822e 100644 --- a/sickbeard/db.py +++ b/sickbeard/db.py @@ -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 diff --git a/sickbeard/generic_queue.py b/sickbeard/generic_queue.py index 862e80cb..f97e348a 100644 --- a/sickbeard/generic_queue.py +++ b/sickbeard/generic_queue.py @@ -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""" diff --git a/sickbeard/name_parser/parser.py b/sickbeard/name_parser/parser.py index 0fedbab7..02e72aa6 100644 --- a/sickbeard/name_parser/parser.py +++ b/sickbeard/name_parser/parser.py @@ -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): diff --git a/sickbeard/postProcessor.py b/sickbeard/postProcessor.py index c4938ec6..190b84d5 100644 --- a/sickbeard/postProcessor.py +++ b/sickbeard/postProcessor.py @@ -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): diff --git a/sickbeard/scene_exceptions.py b/sickbeard/scene_exceptions.py index 91c02825..4ddc8f0a 100644 --- a/sickbeard/scene_exceptions.py +++ b/sickbeard/scene_exceptions.py @@ -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 diff --git a/sickbeard/search.py b/sickbeard/search.py index 89590a53..976555cd 100644 --- a/sickbeard/search.py +++ b/sickbeard/search.py @@ -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':