Revert "Attempt to fix items getting deleted on second sync"
This reverts commit 459bd72299
.
This commit is contained in:
parent
459bd72299
commit
056463da55
4 changed files with 60 additions and 78 deletions
|
@ -76,7 +76,6 @@ class ItemBase(object):
|
|||
self.plexconn.close()
|
||||
self.kodiconn.close()
|
||||
self.artconn.close()
|
||||
LOG.debug('Committed and closed DBs')
|
||||
return self
|
||||
|
||||
def commit(self):
|
||||
|
|
|
@ -11,7 +11,7 @@ from StringIO import StringIO
|
|||
|
||||
from .get_metadata import GetMetadataTask, reset_collections
|
||||
from .process_metadata import InitNewSection, UpdateLastSync, ProcessMetadata, \
|
||||
DeleteItem, UpdateUserdata, StopSection
|
||||
DeleteItem, UpdateUserdata
|
||||
from . import common, sections
|
||||
from .. import utils, timing, backgroundthread, variables as v, app
|
||||
from .. import plex_functions as PF, itemtypes
|
||||
|
@ -38,7 +38,6 @@ class FullSync(common.libsync_mixin):
|
|||
self.callback = callback
|
||||
self.show_dialog = show_dialog
|
||||
self.queue = None
|
||||
self.out_queue = None
|
||||
self.process_thread = None
|
||||
self.current_sync = None
|
||||
self.plexdb = None
|
||||
|
@ -72,11 +71,10 @@ class FullSync(common.libsync_mixin):
|
|||
Removes all the items that have NOT been updated (last_sync timestamp
|
||||
is different)
|
||||
"""
|
||||
for plex_id, last_sync in self.plexdb.plex_id_by_last_sync(self.plex_type,
|
||||
for plex_id in self.plexdb.plex_id_by_last_sync(self.plex_type,
|
||||
self.current_sync):
|
||||
if self.isCanceled():
|
||||
return
|
||||
LOG.debug('process_delete %s, %s', plex_id, last_sync)
|
||||
self.queue.put(DeleteItem(plex_id))
|
||||
|
||||
@utils.log_time
|
||||
|
@ -114,6 +112,12 @@ class FullSync(common.libsync_mixin):
|
|||
except RuntimeError:
|
||||
LOG.error('Could not entirely process section %s', section)
|
||||
return False
|
||||
LOG.debug('Waiting for download threads to finish')
|
||||
while self.threader.threader.working():
|
||||
app.APP.monitor.waitForAbort(0.1)
|
||||
LOG.debug('Waiting for processing thread to finish section')
|
||||
self.queue.join()
|
||||
reset_collections()
|
||||
try:
|
||||
# Sync playstate of every item
|
||||
iterator = section['iterator_2']
|
||||
|
@ -124,23 +128,9 @@ class FullSync(common.libsync_mixin):
|
|||
section['section_id'],
|
||||
section['plex_type'])
|
||||
self.queue.put(queue_info)
|
||||
# We cannot safely use queue.join(), so use another queue
|
||||
# This will block!
|
||||
LOG.debug('Waiting for processing to finish process_item part')
|
||||
self.out_queue.get()
|
||||
self.out_queue.task_done()
|
||||
LOG.debug('process_item part done')
|
||||
reset_collections()
|
||||
# Delete movies that are not on Plex anymore
|
||||
self.process_delete()
|
||||
self.out_queue.get()
|
||||
self.out_queue.task_done()
|
||||
if section['plex_type'] != v.PLEX_TYPE_ARTIST:
|
||||
self.process_playstate(iterator)
|
||||
self.queue.put(StopSection())
|
||||
# This will block until processing thread has reached StopSection
|
||||
self.out_queue.get()
|
||||
self.out_queue.task_done()
|
||||
self.queue.join()
|
||||
except RuntimeError:
|
||||
LOG.error('Could not process playstate for section %s', section)
|
||||
return False
|
||||
|
@ -206,6 +196,8 @@ class FullSync(common.libsync_mixin):
|
|||
# Now do the heavy lifting
|
||||
if self.isCanceled() or not self.process_section(section):
|
||||
return False
|
||||
# Delete movies that are not on Plex anymore
|
||||
self.process_delete()
|
||||
iterator_queue.task_done()
|
||||
return True
|
||||
|
||||
|
@ -226,9 +218,7 @@ class FullSync(common.libsync_mixin):
|
|||
try:
|
||||
# Fire up our single processing thread
|
||||
self.queue = backgroundthread.Queue.Queue(maxsize=1000)
|
||||
self.out_queue = backgroundthread.Queue.Queue()
|
||||
self.processing_thread = ProcessMetadata(self.queue,
|
||||
self.out_queue,
|
||||
self.current_sync,
|
||||
self.show_dialog)
|
||||
self.processing_thread.start()
|
||||
|
|
|
@ -29,10 +29,6 @@ class InitNewSection(object):
|
|||
self.plex_type = plex_type
|
||||
|
||||
|
||||
class StopSection(object):
|
||||
pass
|
||||
|
||||
|
||||
class UpdateUserdata(object):
|
||||
def __init__(self, xml_item):
|
||||
self.xml_item = xml_item
|
||||
|
@ -53,11 +49,16 @@ class ProcessMetadata(common.libsync_mixin, backgroundthread.KillableThread):
|
|||
Not yet implemented for more than 1 thread - if ever. Only to be called by
|
||||
ONE thread!
|
||||
Processes the XML metadata in the queue
|
||||
|
||||
Input:
|
||||
queue: Queue.Queue() object that you'll need to fill up with
|
||||
the downloaded XML eTree objects
|
||||
item_class: as used to call functions in itemtypes.py e.g. 'Movies' =>
|
||||
itemtypes.Movies()
|
||||
"""
|
||||
def __init__(self, queue, out_queue, last_sync, show_dialog):
|
||||
def __init__(self, queue, last_sync, show_dialog):
|
||||
self._canceled = False
|
||||
self.queue = queue
|
||||
self.out_queue = out_queue
|
||||
self.last_sync = last_sync
|
||||
self.show_dialog = show_dialog
|
||||
self.total = 0
|
||||
|
@ -104,58 +105,50 @@ class ProcessMetadata(common.libsync_mixin, backgroundthread.KillableThread):
|
|||
# Init with the very first library section. This will block!
|
||||
section = self.queue.get()
|
||||
self.queue.task_done()
|
||||
if section is None:
|
||||
return
|
||||
while not self.isCanceled():
|
||||
if section is None:
|
||||
break
|
||||
if isinstance(section, StopSection):
|
||||
section = self.queue.get()
|
||||
continue
|
||||
else:
|
||||
LOG.debug('Start processing section %s (%ss)',
|
||||
section.name, section.plex_type)
|
||||
self.current = 1
|
||||
self.processed = 0
|
||||
self.total = section.total
|
||||
self.section_name = section.name
|
||||
self.section_type_text = utils.lang(
|
||||
v.TRANSLATION_FROM_PLEXTYPE[section.plex_type])
|
||||
profile = Profile()
|
||||
profile.enable()
|
||||
with section.context(self.last_sync) as context:
|
||||
while not self.isCanceled():
|
||||
# grabs item from queue. This will block!
|
||||
item = self.queue.get()
|
||||
if isinstance(item, dict):
|
||||
context.add_update(item['xml'][0],
|
||||
section_name=section.name,
|
||||
section_id=section.id,
|
||||
children=item['children'])
|
||||
self.title = item['xml'][0].get('title')
|
||||
self.processed += 1
|
||||
elif isinstance(item, UpdateLastSync):
|
||||
LOG.debug('UpdateLastSync to %s', self.last_sync)
|
||||
context.plexdb.update_last_sync(item.plex_id,
|
||||
section.plex_type,
|
||||
self.last_sync)
|
||||
LOG.debug('Item now: %s', context.plexdb.movie(item.plex_id))
|
||||
elif isinstance(item, UpdateUserdata):
|
||||
context.update_userdata(item.xml_item, section.plex_type)
|
||||
elif (isinstance(item, InitNewSection) or
|
||||
isinstance(item, StopSection) or
|
||||
item is None):
|
||||
section = item
|
||||
self.queue.task_done()
|
||||
break
|
||||
else:
|
||||
context.remove(item.plex_id, plex_type=section.plex_type)
|
||||
self.update_progressbar()
|
||||
self.current += 1
|
||||
if self.processed == 500:
|
||||
self.processed = 0
|
||||
context.commit()
|
||||
LOG.debug('Start processing section %s (%ss)',
|
||||
section.name, section.plex_type)
|
||||
self.current = 1
|
||||
self.processed = 0
|
||||
self.total = section.total
|
||||
self.section_name = section.name
|
||||
self.section_type_text = utils.lang(
|
||||
v.TRANSLATION_FROM_PLEXTYPE[section.plex_type])
|
||||
profile = Profile()
|
||||
profile.enable()
|
||||
with section.context(self.last_sync) as context:
|
||||
while not self.isCanceled():
|
||||
# grabs item from queue. This will block!
|
||||
item = self.queue.get()
|
||||
if isinstance(item, dict):
|
||||
context.add_update(item['xml'][0],
|
||||
section_name=section.name,
|
||||
section_id=section.id,
|
||||
children=item['children'])
|
||||
self.title = item['xml'][0].get('title')
|
||||
self.processed += 1
|
||||
elif isinstance(item, UpdateLastSync):
|
||||
context.plexdb.update_last_sync(item.plex_id,
|
||||
section.plex_type,
|
||||
self.last_sync)
|
||||
elif isinstance(item, UpdateUserdata):
|
||||
context.update_userdata(item.xml_item, section.plex_type)
|
||||
elif isinstance(item, InitNewSection) or item is None:
|
||||
section = item
|
||||
self.queue.task_done()
|
||||
# Tell the main sync thread that we're done with this section
|
||||
self.out_queue.put(None)
|
||||
break
|
||||
else:
|
||||
context.remove(item.plex_id, plex_type=section.plex_type)
|
||||
self.update_progressbar()
|
||||
self.current += 1
|
||||
if self.processed == 500:
|
||||
self.processed = 0
|
||||
context.commit()
|
||||
self.queue.task_done()
|
||||
profile.disable()
|
||||
string_io = StringIO()
|
||||
stats = Stats(profile, stream=string_io).sort_stats('cumulative')
|
||||
|
|
|
@ -93,8 +93,8 @@ class PlexDBBase(object):
|
|||
"""
|
||||
Returns an iterator for all items where the last_sync is NOT identical
|
||||
"""
|
||||
return (x for x in
|
||||
self.cursor.execute('SELECT plex_id, last_sync FROM %s WHERE last_sync <> ?' % plex_type,
|
||||
return (x[0] for x in
|
||||
self.cursor.execute('SELECT plex_id FROM %s WHERE last_sync <> ?' % plex_type,
|
||||
(last_sync, )))
|
||||
|
||||
def checksum(self, plex_id, plex_type):
|
||||
|
|
Loading…
Reference in a new issue