From 6b5c87d5c35ebbac6f7fbcac1a722bd0b3148e04 Mon Sep 17 00:00:00 2001 From: Michaƫl Ball Date: Sun, 9 Aug 2015 14:44:55 +0100 Subject: Improve performance - introduce transactions --- models/album.py | 4 ++++ models/artist.py | 6 +++++- models/track.py | 8 ++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/models/album.py b/models/album.py index b2625db..216b615 100644 --- a/models/album.py +++ b/models/album.py @@ -24,6 +24,8 @@ class Album(): for track in self.tracks: track.delete() + cursor.execute("BEGIN TRANSACTION") + delete_sql = "DELETE FROM album WHERE id = ?" cursor.execute(delete_sql, (self.id,)) @@ -33,6 +35,8 @@ class Album(): delete_artist_rel_sql = "DELETE FROM album_artist WHERE album_id = ?" cursor.execute(delete_artist_rel_sql, (self.id,)) + cursor.execute("COMMIT TRANSACTION") + return True @property diff --git a/models/artist.py b/models/artist.py index 1afd516..2e69354 100644 --- a/models/artist.py +++ b/models/artist.py @@ -25,6 +25,8 @@ class Artist: for album in self.albums: album.delete() + cursor.execute("BEGIN TRANSACTION") + delete_sql = "DELETE FROM artist WHERE id = ?" cursor.execute(delete_sql, (self.id,)) @@ -34,6 +36,8 @@ class Artist: delete_album_rel_sql = "DELETE FROM album_artist WHERE artist_id = ?" cursor.execute(delete_album_rel_sql, (self.id,)) + cursor.execute("COMMIT TRANSACTION") + return True @property @@ -152,4 +156,4 @@ class Artist: musicbrainz_artistid=row[3]) ) - return artist + return artists diff --git a/models/track.py b/models/track.py index 854b3ee..8b16d26 100644 --- a/models/track.py +++ b/models/track.py @@ -72,6 +72,8 @@ class Track: db = DbManager() c = db.cursor() + c.execute("BEGIN TRANSACTION") + artist_names = metadata["artist"] musicbrainz_artist_ids = [] artistsorts = [] @@ -257,6 +259,8 @@ class Track: except apsw.ConstraintError: pass + c.execute("COMMIT TRANSACTION") + return True def save(self): @@ -334,6 +338,8 @@ class Track: db = DbManager() c = db.cursor() + c.execute("BEGIN TRANSACTION") + artist_names = metadata["artist"] musicbrainz_artist_ids = [] artistsorts = [] @@ -530,4 +536,6 @@ class Track: except apsw.ConstraintError: pass + c.execute("COMMIT TRANSACTION") + return True -- cgit v1.2.3