perform all database commits at once instead of 1 by 1

This commit is contained in:
Marcel van der Veldt 2015-05-02 22:46:12 +02:00
parent e637af1b78
commit 383fb37ca3
3 changed files with 19 additions and 25 deletions

View file

@ -83,7 +83,7 @@ class LibrarySync():
addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon
addon.setSetting("SyncInstallRunDone", "true")
# Force refresh the library
# Commit all DB changes at once and Force refresh the library
xbmc.executebuiltin("UpdateLibrary(video)")
# set prop to show we have run for the first time
@ -92,6 +92,7 @@ class LibrarySync():
finally:
WINDOW.setProperty("SyncDatabaseRunning", "false")
utils.logMsg("Sync DB", "syncDatabase Exiting", 0)
cursor.close()
if(pDialog != None):
@ -149,6 +150,9 @@ class LibrarySync():
WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
### commit all changes to database ###
connection.commit()
def MusicVideosFullSync(self,connection,cursor, pDialog):
allKodiMusicvideoIds = list()
@ -195,6 +199,9 @@ class LibrarySync():
WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
### commit all changes to database ###
connection.commit()
def TvShowsFullSync(self,connection,cursor,pDialog):
views = ReadEmbyDB().getCollections("tvshows")
@ -252,6 +259,9 @@ class LibrarySync():
WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
### commit all changes to database ###
connection.commit()
def EpisodesFullSync(self,connection,cursor,showId):
WINDOW = xbmcgui.Window( 10000 )
@ -300,6 +310,7 @@ class LibrarySync():
WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
def IncrementalSync(self, itemList):
#this will only perform sync for items received by the websocket
addon = xbmcaddon.Addon(id='plugin.video.emby')
@ -356,6 +367,9 @@ class LibrarySync():
if not item.get('IsFolder'):
WriteKodiDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor)
### commit all changes to database ###
connection.commit()
finally:
cursor.close()
xbmc.executebuiltin("UpdateLibrary(video)")

View file

@ -180,11 +180,12 @@ class WebSocketThread(threading.Thread):
self.update_items(itemsToUpdate)
def remove_items(self, itemsRemoved):
for item in itemsRemoved:
connection = utils.KodiSQL()
cursor = connection.cursor()
for item in itemsRemoved:
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0)
WriteKodiDB().deleteItemFromKodiLibrary(item, connection, cursor)
connection.commit()
cursor.close()
def update_items(self, itemsToUpdate):

View file

@ -199,9 +199,6 @@ class WriteKodiDB():
total = int(round(float(timeInfo.get("TotalTime"))))*60
self.setKodiResumePoint(fileid, resume, total, cursor)
#commit changes and return the id
connection.commit()
return movieid
def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor):
@ -336,9 +333,6 @@ class WriteKodiDB():
total = int(round(float(timeInfo.get("TotalTime"))))*60
self.setKodiResumePoint(fileid, resume, total, cursor)
#commit changes and return the id
connection.commit()
def addOrUpdateTvShowToKodiLibrary( self, embyId, connection, cursor, viewTag ):
addon = xbmcaddon.Addon(id='plugin.video.emby')
@ -463,8 +457,6 @@ class WriteKodiDB():
#update season details
self.updateSeasons(MBitem["Id"], showid, connection, cursor)
#commit changes and return the id
connection.commit()
def addMusicVideoToKodiLibrary( self, MBitem, connection, cursor ):
@ -530,12 +522,6 @@ class WriteKodiDB():
pathsql="insert into musicvideo(idMVideo, idFile, c00, c04, c08, c23) values(?, ?, ?, ?, ?, ?)"
cursor.execute(pathsql, (musicvideoid, fileid, title, runtime, plot, MBitem["Id"]))
try:
connection.commit()
utils.logMsg("Emby","Added musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
except:
utils.logMsg("Emby","Error adding musicvideo to Kodi Library",MBitem["Id"] + " - " + MBitem["Name"])
actionPerformed = False
def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor):
@ -676,9 +662,6 @@ class WriteKodiDB():
#update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary"), episodeid, "episode", "thumb", cursor)
#commit changes
connection.commit()
def deleteItemFromKodiLibrary(self, id, connection, cursor ):
cursor.execute("SELECT kodi_id, media_type FROM emby WHERE emby_id=?", (id,))
@ -702,8 +685,6 @@ class WriteKodiDB():
#delete the record in emby table
cursor.execute("DELETE FROM emby WHERE emby_id = ?", (id,))
connection.commit()
def updateSeasons(self,embyTvShowId, kodiTvShowId, connection, cursor):
seasonData = ReadEmbyDB().getTVShowSeasons(embyTvShowId)
@ -1058,8 +1039,6 @@ class WriteKodiDB():
result = cursor.fetchone()
if result != None:
setid = result[0]
connection.commit()
return True