diff options
author | Michaël Ball <michael.ball@gmail.com> | 2015-08-09 14:44:55 +0100 |
---|---|---|
committer | Michaël Ball <michael.ball@gmail.com> | 2015-08-09 14:44:55 +0100 |
commit | 6b5c87d5c35ebbac6f7fbcac1a722bd0b3148e04 (patch) | |
tree | efc2b776dad1307d4b8b78a517e9789852b4dc31 /models | |
parent | 122ec1c9b283776b8f1fea5559d4317bdba5b977 (diff) |
Improve performance - introduce transactions
Diffstat (limited to 'models')
-rw-r--r-- | models/album.py | 4 | ||||
-rw-r--r-- | models/artist.py | 6 | ||||
-rw-r--r-- | models/track.py | 8 |
3 files changed, 17 insertions, 1 deletions
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 |