Fix PKC not deleting all the items it should

This commit is contained in:
croneter 2019-02-02 11:24:55 +01:00
parent b3402fc3d5
commit 3a9fcacd5c
2 changed files with 16 additions and 10 deletions

View file

@ -372,12 +372,17 @@ class FullSync(common.fullsync_mixin):
])
for plex_type, context in kinds:
# Delete movies that are not on Plex anymore
while True:
with context(self.current_sync) as ctx:
for plex_id in ctx.plexdb.plex_id_by_last_sync(plex_type,
self.current_sync):
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

View file

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