From b3752ebea09d983343e45eb30aa2857a35df1bd7 Mon Sep 17 00:00:00 2001 From: pannal Date: Tue, 7 Mar 2017 10:04:44 +0100 Subject: [PATCH] run migrations in separate thread; don't fail on already run history migration --- Contents/Code/__init__.py | 8 +++----- Contents/Code/support/data.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Contents/Code/__init__.py b/Contents/Code/__init__.py index d987740e..b25b1bb3 100755 --- a/Contents/Code/__init__.py +++ b/Contents/Code/__init__.py @@ -33,7 +33,7 @@ from support.config import config from support.lib import get_intent from support.helpers import track_usage, get_title_for_video_metadata, get_identifier, cast_bool from support.history import get_history -from support.data import migrate +from support.data import dispatch_migrate def Start(): @@ -55,10 +55,8 @@ def Start(): del Dict["menu_history"][key] # run migrations - try: - migrate() - except: - Log.Error("Migration failed: %s" % traceback.format_exc()) + if "subs" in Dict or "history" in Dict: + Thread.Create(dispatch_migrate) # clear old task data scheduler.clear_task_data() diff --git a/Contents/Code/support/data.py b/Contents/Code/support/data.py index cde1d40d..b08fcca3 100644 --- a/Contents/Code/support/data.py +++ b/Contents/Code/support/data.py @@ -1,5 +1,11 @@ # coding=utf-8 -from urllib2 import URLError + + +def dispatch_migrate(): + try: + migrate() + except: + Log.Error("Migration failed: %s" % traceback.format_exc()) def migrate(): @@ -9,7 +15,7 @@ def migrate(): """ # migrate subtitle history from Dict to Data - if "history" in Dict and Dict["history"]["history_items"]: + if "history" in Dict and Dict["history"].get("history_items"): Log.Debug("Running migration for history data") from support.history import get_history history = get_history() @@ -32,7 +38,7 @@ def migrate(): for video_id, parts in Dict["subs"].iteritems(): try: item = get_item(video_id) - except URLError: + except: continue if not item: