TO BE CHECKED: better method to delete obsolete fileIds

This commit is contained in:
croneter 2019-04-07 11:37:31 +02:00
parent dfcfa0edab
commit d7541b7f74
2 changed files with 13 additions and 11 deletions

View file

@ -178,11 +178,13 @@ class KodiVideoDB(common.KodiDBBase):
'plugin://plugin.video.plexkodiconnect'
These entries should be deleted as they're created falsely by Kodi.
"""
return (x[0] for x in self.cursor.execute('''
SELECT idFile FROM files
WHERE dateAdded IS NULL
AND strFilename LIKE \'plugin://plugin.video.plexkodiconnect%\'
'''))
return (x[0] for x in self.cursor.execute("""
SELECT files.idFile
FROM files
LEFT JOIN path ON path.idPath = files.idPath
WHERE files.dateAdded IS NULL
AND path.strPath LIKE \'%plex.direct%\'
"""))
def show_id_from_path(self, path):
"""

View file

@ -517,13 +517,13 @@ def _clean_file_table():
This function tries for at most 5 seconds to clean the file table.
"""
LOG.debug('Start cleaning Kodi files table')
app.APP.monitor.waitForAbort(2)
app.APP.monitor.waitForAbort(1)
try:
with kodi_db.KodiVideoDB() as kodidb_1:
with kodi_db.KodiVideoDB(lock=False) as kodidb_2:
for file_id in kodidb_1.obsolete_file_ids():
LOG.debug('Removing obsolete Kodi file_id %s', file_id)
kodidb_2.remove_file(file_id, remove_orphans=False)
with kodi_db.KodiVideoDB() as kodidb:
file_ids = list(kodidb.obsolete_file_ids())
LOG.debug('Obsolete kodi file_ids: %s', file_ids)
for file_id in file_ids:
kodidb.remove_file(file_id)
except utils.OperationalError:
LOG.debug('Database was locked, unable to clean file table')
else: