delete old track_genre and album_genre tags while scanning

This commit is contained in:
sentriz
2020-12-30 20:59:31 +00:00
parent 8492561d2b
commit a37993e24f
3 changed files with 15 additions and 1 deletions

1
go.mod
View File

@@ -22,7 +22,6 @@ require (
github.com/kr/pretty v0.1.0 // indirect
github.com/mewkiz/flac v1.0.6 // indirect
github.com/mewkiz/pkg v0.0.0-20200702171441-dd47075182ea // indirect
github.com/mattn/go-sqlite3 v1.14.6 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/nicksellen/audiotags v0.0.0-20160226222119-94015fa599bd

1
go.sum
View File

@@ -115,6 +115,7 @@ github.com/lucasb-eyer/go-colorful v0.0.0-20181028223441-12d3b2882a08/go.mod h1:
github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v1.14.0/go.mod h1:JIl7NbARA7phWnGvh0LKTyg7S9BA+6gx71ShQilpsus=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v2.0.1+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
github.com/mattn/go-sqlite3 v2.0.3+incompatible h1:gXHsfypPkaMZrKbD5209QV9jbUTJKjyR5WD3HYQSd+U=
github.com/mattn/go-sqlite3 v2.0.3+incompatible/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=

View File

@@ -459,6 +459,13 @@ func (s *Scanner) handleTrack(it *item) error {
if err := s.trTx.Save(track).Error; err != nil {
return fmt.Errorf("writing track table: %w", err)
}
err = s.trTx.
Where("track_id=?", track.ID).
Delete(db.TrackGenre{}).
Error
if err != nil {
return fmt.Errorf("delete old track genre records: %w", err)
}
err = s.trTx.InsertBulkLeftMany(
"track_genres",
[]string{"track_id", "genre_id"},
@@ -476,6 +483,13 @@ func (s *Scanner) handleTrack(it *item) error {
// the folder hasn't been modified or already has it's tags
return nil
}
err = s.trTx.
Where("album_id=?", folder.ID).
Delete(db.AlbumGenre{}).
Error
if err != nil {
return fmt.Errorf("delete old album genre records: %w", err)
}
err = s.trTx.InsertBulkLeftMany(
"album_genres",
[]string{"album_id", "genre_id"},