From 3a9fcacd5c3af84e0ef99aae9fd17c82a8ae3b44 Mon Sep 17 00:00:00 2001 From: croneter Date: Sat, 2 Feb 2019 11:24:55 +0100 Subject: [PATCH] Fix PKC not deleting all the items it should --- resources/lib/library_sync/full_sync.py | 17 +++++++++++------ resources/lib/plex_db/common.py | 9 +++++---- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/resources/lib/library_sync/full_sync.py b/resources/lib/library_sync/full_sync.py index 6e2b1119..83c0528b 100644 --- a/resources/lib/library_sync/full_sync.py +++ b/resources/lib/library_sync/full_sync.py @@ -372,12 +372,17 @@ class FullSync(common.fullsync_mixin): ]) for plex_type, context in kinds: # Delete movies that are not on Plex anymore - with context(self.current_sync) as ctx: - for plex_id in ctx.plexdb.plex_id_by_last_sync(plex_type, - self.current_sync): - if self.isCanceled(): - return False - ctx.remove(plex_id, plex_type) + while True: + with context(self.current_sync) as ctx: + plex_ids = list(ctx.plexdb.plex_id_by_last_sync(plex_type, + self.current_sync, + BATCH_SIZE)) + for plex_id in plex_ids: + if self.isCanceled(): + return False + ctx.remove(plex_id, plex_type) + if len(plex_ids) < BATCH_SIZE: + break LOG.debug('Done deleting') return True diff --git a/resources/lib/plex_db/common.py b/resources/lib/plex_db/common.py index 0ce2af9b..dcacabfd 100644 --- a/resources/lib/plex_db/common.py +++ b/resources/lib/plex_db/common.py @@ -100,13 +100,14 @@ class PlexDBBase(object): method = getattr(self, 'entry_to_%s' % v.PLEX_TYPE_FROM_KODI_TYPE[kodi_type]) return method(self.cursor.fetchone()) - def plex_id_by_last_sync(self, plex_type, last_sync): + def plex_id_by_last_sync(self, plex_type, last_sync, limit): """ Returns an iterator for all items where the last_sync is NOT identical """ - return (x[0] for x in - self.cursor.execute('SELECT plex_id FROM %s WHERE last_sync <> ?' % plex_type, - (last_sync, ))) + query = ''' + SELECT plex_id FROM %s WHERE last_sync <> ? LIMIT %s + ''' % (plex_type, limit) + return (x[0] for x in self.cursor.execute(query, (last_sync, ))) def checksum(self, plex_id, plex_type): """