Speed up and simplify sync of playstates
This commit is contained in:
parent
654748218e
commit
136af95351
1 changed files with 15 additions and 20 deletions
|
@ -20,6 +20,7 @@ if common.PLAYLIST_SYNC_ENABLED:
|
||||||
LOG = getLogger('PLEX.sync.full_sync')
|
LOG = getLogger('PLEX.sync.full_sync')
|
||||||
# How many items will be put through the processing chain at once?
|
# How many items will be put through the processing chain at once?
|
||||||
BATCH_SIZE = 250
|
BATCH_SIZE = 250
|
||||||
|
PLAYSTATE_BATCH_SIZE = 5000
|
||||||
# Size of queue for xmls to be downloaded from PMS for/and before processing
|
# Size of queue for xmls to be downloaded from PMS for/and before processing
|
||||||
QUEUE_BUFFER = 50
|
QUEUE_BUFFER = 50
|
||||||
# Max number of xmls held in memory
|
# Max number of xmls held in memory
|
||||||
|
@ -123,26 +124,20 @@ class FullSync(common.LibrarySyncMixin, backgroundthread.KillableThread):
|
||||||
LOG.debug('Processing %s playstates for library section %s',
|
LOG.debug('Processing %s playstates for library section %s',
|
||||||
section.number_of_items, section)
|
section.number_of_items, section)
|
||||||
try:
|
try:
|
||||||
iterator = section.iterator
|
with section.context(self.current_time) as context:
|
||||||
iterator = common.tag_last(iterator)
|
for xml in section.iterator:
|
||||||
last = True
|
section.count += 1
|
||||||
while not self.should_cancel():
|
if not context.update_userdata(xml, section.plex_type):
|
||||||
with section.context(self.current_time) as itemtype:
|
# Somehow did not sync this item yet
|
||||||
for last, xml_item in iterator:
|
context.add_update(xml,
|
||||||
section.count += 1
|
section_name=section.name,
|
||||||
if not itemtype.update_userdata(xml_item, section.plex_type):
|
section_id=section.section_id)
|
||||||
# Somehow did not sync this item yet
|
context.plexdb.update_last_sync(int(xml.attrib['ratingKey']),
|
||||||
itemtype.add_update(xml_item,
|
section.plex_type,
|
||||||
section_name=section.name,
|
self.current_time)
|
||||||
section_id=section.section_id)
|
self.update_progressbar(section, '', section.count)
|
||||||
itemtype.plexdb.update_last_sync(int(xml_item.attrib['ratingKey']),
|
if section.count % PLAYSTATE_BATCH_SIZE == 0:
|
||||||
section.plex_type,
|
context.commit()
|
||||||
self.current_time)
|
|
||||||
self.update_progressbar(section, '', section.count)
|
|
||||||
if section.count % (10 * BATCH_SIZE) == 0:
|
|
||||||
break
|
|
||||||
if last:
|
|
||||||
break
|
|
||||||
except RuntimeError:
|
except RuntimeError:
|
||||||
LOG.error('Could not entirely process section %s', section)
|
LOG.error('Could not entirely process section %s', section)
|
||||||
self.successful = False
|
self.successful = False
|
||||||
|
|
Loading…
Reference in a new issue