Further speed up add_file

This commit is contained in:
croneter 2018-11-07 13:37:37 +01:00
parent 05c96dc1c6
commit 2319d2fc9c

View file

@ -191,18 +191,18 @@ class KodiDBMethods(object):
Adds the filename [unicode] to the table files if not already added Adds the filename [unicode] to the table files if not already added
and returns the idFile. and returns the idFile.
""" """
query = 'SELECT idFile FROM files WHERE idPath = ? AND strFilename = ?' self.cursor.execute('SELECT idFile FROM files WHERE idPath = ? AND strFilename = ?',
self.cursor.execute(query, (path_id, filename)) (path_id, filename))
try: try:
file_id = self.cursor.fetchone()[0] file_id = self.cursor.fetchone()[0]
except TypeError: except TypeError:
self.cursor.execute('SELECT COALESCE(MAX(idFile), 0) FROM files') self.cursor.execute('SELECT COALESCE(MAX(idFile), 0) FROM files')
file_id = self.cursor.fetchone()[0] + 1 file_id = self.cursor.fetchone()[0] + 1
query = ''' self.cursor.execute('''
INSERT INTO files(idFile, idPath, strFilename, dateAdded) INSERT INTO files(
VALUES (?, ?, ?, ?) idFile, idPath, strFilename, dateAdded)
''' VALUES (?, ?, ?, ?)
self.cursor.execute(query, ''',
(file_id, path_id, filename, date_added)) (file_id, path_id, filename, date_added))
return file_id return file_id