Optimize sync startup

This commit is contained in:
croneter 2018-10-25 12:46:57 +02:00
parent 2a97678ba4
commit c2efe0d57f

View file

@ -545,17 +545,17 @@ class Sync(backgroundthread.KillableThread):
def _run_internal(self): def _run_internal(self):
LOG.info("---===### Starting Sync ###===---") LOG.info("---===### Starting Sync ###===---")
self.force_dialog = False
install_sync_done = utils.settings('SyncInstallRunDone') == 'true' install_sync_done = utils.settings('SyncInstallRunDone') == 'true'
playlist_monitor = None playlist_monitor = None
initial_sync_done = False initial_sync_done = False
kodi_db_version_checked = False
last_processing = 0 last_processing = 0
last_time_sync = 0 last_time_sync = 0
one_day_in_seconds = 60 * 60 * 24 one_day_in_seconds = 60 * 60 * 24
# Link to Websocket queue # Link to Websocket queue
queue = state.WEBSOCKET_QUEUE queue = state.WEBSOCKET_QUEUE
# Kodi Version supported by PKC?
if (not path_ops.exists(v.DB_VIDEO_PATH) or if (not path_ops.exists(v.DB_VIDEO_PATH) or
not path_ops.exists(v.DB_TEXTURE_PATH) or not path_ops.exists(v.DB_TEXTURE_PATH) or
(state.ENABLE_MUSIC and not path_ops.exists(v.DB_MUSIC_PATH))): (state.ENABLE_MUSIC and not path_ops.exists(v.DB_MUSIC_PATH))):
@ -566,8 +566,24 @@ class Sync(backgroundthread.KillableThread):
# "Current Kodi version is unsupported, cancel lib sync" # "Current Kodi version is unsupported, cancel lib sync"
utils.messageDialog(utils.lang(29999), utils.lang(39403)) utils.messageDialog(utils.lang(29999), utils.lang(39403))
return return
# Check whether we need to reset the Kodi DB
# Do some initializing if install_sync_done:
current_version = utils.settings('dbCreatedWithVersion')
if not utils.compare_version(current_version,
v.MIN_DB_VERSION):
LOG.warn("Db version out of date: %s minimum version "
"required: %s", current_version, v.MIN_DB_VERSION)
# DB out of date. Proceed to recreate?
if not utils.yesno_dialog(utils.lang(29999),
utils.lang(39401)):
LOG.warn("Db version out of date! USER IGNORED!")
# PKC may not work correctly until reset
utils.messageDialog(utils.lang(29999),
'%s%s' % (utils.lang(29999),
utils.lang(39402)))
else:
utils.reset(ask_user=False)
return
# Ensure that Plex DB is set-up # Ensure that Plex DB is set-up
plex_db.initialize() plex_db.initialize()
# Hack to speed up look-ups for actors (giant table!) # Hack to speed up look-ups for actors (giant table!)
@ -590,6 +606,7 @@ class Sync(backgroundthread.KillableThread):
if not install_sync_done: if not install_sync_done:
# Very FIRST sync ever upon installation or reset of Kodi DB # Very FIRST sync ever upon installation or reset of Kodi DB
self.force_dialog = True
set_library_scan_toggle() set_library_scan_toggle()
# Initialize time offset Kodi - PMS # Initialize time offset Kodi - PMS
library_sync.sync_pms_time() library_sync.sync_pms_time()
@ -602,9 +619,9 @@ class Sync(backgroundthread.KillableThread):
LOG.info('Initial start-up full sync successful') LOG.info('Initial start-up full sync successful')
utils.settings('SyncInstallRunDone', value='true') utils.settings('SyncInstallRunDone', value='true')
install_sync_done = True install_sync_done = True
initial_sync_done = True
utils.settings('dbCreatedWithVersion', v.ADDON_VERSION) utils.settings('dbCreatedWithVersion', v.ADDON_VERSION)
self.force_dialog = False self.force_dialog = False
kodi_db_version_checked = True
if library_sync.PLAYLIST_SYNC_ENABLED: if library_sync.PLAYLIST_SYNC_ENABLED:
from . import playlists from . import playlists
playlist_monitor = playlists.kodi_playlist_monitor() playlist_monitor = playlists.kodi_playlist_monitor()
@ -612,29 +629,8 @@ class Sync(backgroundthread.KillableThread):
self.fanartthread.start() self.fanartthread.start()
else: else:
LOG.error('Initial start-up full sync unsuccessful') LOG.error('Initial start-up full sync unsuccessful')
xbmc.executebuiltin('InhibitIdleShutdown(false)')
elif not kodi_db_version_checked:
# Install sync was already done, don't force-show dialogs
self.force_dialog = False self.force_dialog = False
# Verify the validity of the database xbmc.executebuiltin('InhibitIdleShutdown(false)')
current_version = utils.settings('dbCreatedWithVersion')
if not utils.compare_version(current_version,
v.MIN_DB_VERSION):
LOG.warn("Db version out of date: %s minimum version "
"required: %s", current_version, v.MIN_DB_VERSION)
# DB out of date. Proceed to recreate?
if not utils.yesno_dialog(utils.lang(29999),
utils.lang(39401)):
LOG.warn("Db version out of date! USER IGNORED!")
# PKC may not work correctly until reset
utils.messageDialog(utils.lang(29999),
'%s%s' % (utils.lang(29999),
utils.lang(39402)))
else:
utils.reset(ask_user=False)
break
kodi_db_version_checked = True
elif not initial_sync_done: elif not initial_sync_done:
# First sync upon PKC restart. Skipped if very first sync upon # First sync upon PKC restart. Skipped if very first sync upon