Fix OperationalError: database is locked
This commit is contained in:
parent
fd542936b8
commit
d16da6fa6f
2 changed files with 51 additions and 34 deletions
|
@ -5,7 +5,8 @@ from logging import getLogger
|
|||
import xbmc
|
||||
|
||||
from .get_metadata import GetMetadataTask, reset_collections
|
||||
from . import common, process_metadata, sections
|
||||
from .process_metadata import InitNewSection, UpdateLastSync, ProcessMetadata
|
||||
from . import common, sections
|
||||
from .. import utils, backgroundthread, variables as v, state
|
||||
from .. import plex_functions as PF, itemtypes
|
||||
from ..plex_db import PlexDB
|
||||
|
@ -51,10 +52,9 @@ class FullSync(common.libsync_mixin):
|
|||
int('%s%s' % (plex_id,
|
||||
xml_item.get('updatedAt',
|
||||
xml_item.get('addedAt', 1541572987)))):
|
||||
# Already got EXACTLY this item in our DB
|
||||
self.plexdb.update_last_sync(plex_id,
|
||||
self.plex_type,
|
||||
self.current_sync)
|
||||
# Already got EXACTLY this item in our DB. BUT need to collect all
|
||||
# DB updates within the same thread
|
||||
self.queue.put(UpdateLastSync(plex_id))
|
||||
return
|
||||
task = GetMetadataTask()
|
||||
task.setup(self.queue, plex_id, self.plex_type, self.get_children)
|
||||
|
@ -103,9 +103,9 @@ class FullSync(common.libsync_mixin):
|
|||
iterator = PF.SectionItems(section['section_id'],
|
||||
plex_type=self.plex_type)
|
||||
# Tell the processing thread about this new section
|
||||
queue_info = process_metadata.InitNewSection(
|
||||
self.context,
|
||||
utils.cast(int, iterator.get('totalSize', 0)),
|
||||
queue_info = InitNewSection(self.context,
|
||||
utils.cast(int,
|
||||
iterator.get('totalSize', 0)),
|
||||
iterator.get('librarySectionTitle'),
|
||||
section['section_id'],
|
||||
self.plex_type)
|
||||
|
@ -130,9 +130,9 @@ class FullSync(common.libsync_mixin):
|
|||
iterator = PF.SectionItems(section['section_id'],
|
||||
plex_type=self.plex_type)
|
||||
# Tell the processing thread that we're syncing playstate
|
||||
queue_info = process_metadata.InitNewSection(
|
||||
self.context,
|
||||
utils.cast(int, iterator.get('totalSize', 0)),
|
||||
queue_info = InitNewSection(self.context,
|
||||
utils.cast(int,
|
||||
iterator.get('totalSize', 0)),
|
||||
iterator.get('librarySectionTitle'),
|
||||
section['section_id'],
|
||||
self.plex_type)
|
||||
|
@ -192,9 +192,10 @@ class FullSync(common.libsync_mixin):
|
|||
return
|
||||
try:
|
||||
# Fire up our single processing thread
|
||||
self.queue = backgroundthread.Queue.Queue(maxsize=400)
|
||||
self.processing_thread = process_metadata.ProcessMetadata(
|
||||
self.queue, self.current_sync, self.show_dialog)
|
||||
self.queue = backgroundthread.Queue.Queue(maxsize=600)
|
||||
self.processing_thread = ProcessMetadata(self.queue,
|
||||
self.current_sync,
|
||||
self.show_dialog)
|
||||
self.processing_thread.start()
|
||||
|
||||
# Actual syncing - do only new items first
|
||||
|
|
|
@ -29,6 +29,11 @@ class InitNewSection(object):
|
|||
self.plex_type = plex_type
|
||||
|
||||
|
||||
class UpdateLastSync(object):
|
||||
def __init__(self, plex_id):
|
||||
self.plex_id = plex_id
|
||||
|
||||
|
||||
class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
||||
"""
|
||||
Not yet implemented for more than 1 thread - if ever. Only to be called by
|
||||
|
@ -48,7 +53,8 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
self.show_dialog = show_dialog
|
||||
self.total = 0
|
||||
self.current = 1
|
||||
self.title = None
|
||||
self.processed = 0
|
||||
self.title = ''
|
||||
self.section_name = None
|
||||
self.dialog = None
|
||||
super(ProcessMetadata, self).__init__()
|
||||
|
@ -81,8 +87,10 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
while not self.isCanceled():
|
||||
if section is None:
|
||||
break
|
||||
LOG.debug('Start processing section %s', section)
|
||||
LOG.debug('Start processing section %s: %s',
|
||||
section.plex_type, section.name)
|
||||
self.current = 1
|
||||
self.processed = 0
|
||||
self.total = section.total
|
||||
self.section_name = section.name
|
||||
profile = Profile()
|
||||
|
@ -95,6 +103,11 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
section = item
|
||||
self.queue.task_done()
|
||||
break
|
||||
elif isinstance(item, UpdateLastSync):
|
||||
context.plexdb.update_last_sync(item.plex_id,
|
||||
section.plex_type,
|
||||
self.last_sync)
|
||||
else:
|
||||
try:
|
||||
context.add_update(item['xml'][0],
|
||||
section_name=section.name,
|
||||
|
@ -105,11 +118,14 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin):
|
|||
notify=True,
|
||||
cancel_sync=True)
|
||||
self.title = item['xml'][0].get('title')
|
||||
self.processed += 1
|
||||
self.update_progressbar()
|
||||
self.current += 1
|
||||
if self.current % 200 == 0:
|
||||
context.plexconn.commit()
|
||||
if self.processed == 500:
|
||||
self.processed = 0
|
||||
context.kodiconn.commit()
|
||||
context.artconn.commit()
|
||||
context.plexconn.commit()
|
||||
self.queue.task_done()
|
||||
profile.disable()
|
||||
string_io = StringIO()
|
||||
|
|
Loading…
Reference in a new issue