Optimize sync loop

This commit is contained in:
croneter 2018-11-05 18:13:57 +01:00
parent d44d6983b3
commit e4c9a7a259

View file

@ -128,12 +128,20 @@ class Sync(backgroundthread.KillableThread):
self.sync_successful = successful self.sync_successful = successful
self.last_full_sync = utils.unix_timestamp() self.last_full_sync = utils.unix_timestamp()
set_library_scan_toggle(boolean=False) set_library_scan_toggle(boolean=False)
if successful:
self.show_kodi_note(utils.lang(39407))
else:
LOG.error('Could not finish scheduled full sync')
self.force_dialog = True
self.show_kodi_note(utils.lang(39410), icon='error')
self.force_dialog = False
# try: # try:
# self.lock.release() # self.lock.release()
# except backgroundthread.threading.ThreadError: # except backgroundthread.threading.ThreadError:
# pass # pass
def start_library_sync(self, show_dialog=None, repair=False, block=False): def start_library_sync(self, show_dialog=None, repair=False, block=False):
set_library_scan_toggle(boolean=True)
show_dialog = show_dialog if show_dialog is not None else state.SYNC_DIALOG show_dialog = show_dialog if show_dialog is not None else state.SYNC_DIALOG
library_sync.start(show_dialog, repair, self.on_library_scan_finished) library_sync.start(show_dialog, repair, self.on_library_scan_finished)
# if block: # if block:
@ -243,8 +251,8 @@ 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()
self.force_dialog = True
# Initialize time offset Kodi - PMS # Initialize time offset Kodi - PMS
library_sync.sync_pms_time() library_sync.sync_pms_time()
last_time_sync = utils.unix_timestamp() last_time_sync = utils.unix_timestamp()
@ -258,7 +266,6 @@ class Sync(backgroundthread.KillableThread):
install_sync_done = True install_sync_done = True
initial_sync_done = True initial_sync_done = True
utils.settings('dbCreatedWithVersion', v.ADDON_VERSION) utils.settings('dbCreatedWithVersion', v.ADDON_VERSION)
self.force_dialog = False
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()
@ -266,13 +273,13 @@ class Sync(backgroundthread.KillableThread):
self.start_image_cache_thread() self.start_image_cache_thread()
else: else:
LOG.error('Initial start-up full sync unsuccessful') LOG.error('Initial start-up full sync unsuccessful')
xbmc.sleep(1000)
self.force_dialog = False self.force_dialog = False
xbmc.executebuiltin('InhibitIdleShutdown(false)') xbmc.executebuiltin('InhibitIdleShutdown(false)')
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
# PKC installation has been completed # PKC installation has been completed
set_library_scan_toggle()
LOG.info('Doing initial sync on Kodi startup') LOG.info('Doing initial sync on Kodi startup')
if state.SUSPEND_SYNC: if state.SUSPEND_SYNC:
LOG.warning('Forcing startup sync even if Kodi is playing') LOG.warning('Forcing startup sync even if Kodi is playing')
@ -288,6 +295,7 @@ class Sync(backgroundthread.KillableThread):
self.start_image_cache_thread() self.start_image_cache_thread()
else: else:
LOG.info('Startup sync has not yet been successful') LOG.info('Startup sync has not yet been successful')
xbmc.sleep(1000)
# Currently no db scan, so we could start a new scan # Currently no db scan, so we could start a new scan
elif state.DB_SCAN is False: elif state.DB_SCAN is False:
@ -303,25 +311,9 @@ class Sync(backgroundthread.KillableThread):
# Standard syncs - don't force-show dialogs # Standard syncs - don't force-show dialogs
now = utils.unix_timestamp() now = utils.unix_timestamp()
self.force_dialog = False
if (now - self.last_full_sync > state.FULL_SYNC_INTERVALL): if (now - self.last_full_sync > state.FULL_SYNC_INTERVALL):
LOG.info('Doing scheduled full library scan') LOG.info('Doing scheduled full library scan')
set_library_scan_toggle() self.start_library_sync()
success = self.maintain_views()
if success:
success = library_sync.start()
if not success and not self.suspend_item_sync():
LOG.error('Could not finish scheduled full sync')
self.force_dialog = True
self.show_kodi_note(utils.lang(39410),
icon='error')
self.force_dialog = False
elif success:
self.last_full_sync = now
# Full library sync finished successfully
self.show_kodi_note(utils.lang(39407))
else:
LOG.info('Full sync interrupted')
elif now - last_time_sync > one_day_in_seconds: elif now - last_time_sync > one_day_in_seconds:
LOG.info('Starting daily time sync') LOG.info('Starting daily time sync')
library_sync.sync_pms_time() library_sync.sync_pms_time()