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): """