scanner: ormise clean artists

This commit is contained in:
sentriz
2020-05-02 23:07:34 +01:00
parent e7c95383be
commit debdfd13ad
2 changed files with 11 additions and 5 deletions

View File

@@ -2,6 +2,9 @@
//nolint:lll
package db
// see this db fiddle to mess around with the schema
// https://www.db-fiddle.com/f/wJ7z8L7mu6ZKaYmWk1xr1p/5
import (
"path"
"strconv"

View File

@@ -132,11 +132,14 @@ func (s *Scanner) cleanFolders() (int, error) {
}
func (s *Scanner) cleanArtists() (int, error) {
q := s.db.Exec(`
DELETE FROM artists
WHERE NOT EXISTS ( SELECT 1 FROM albums
WHERE albums.tag_artist_id=artists.id )
`)
sub := s.db.
Select("1").
Model(&db.Album{}).
Where("albums.tag_artist_id=artists.id").
SubQuery()
q := s.db.
Where("NOT EXISTS ?", sub).
Delete(&db.Artist{})
return int(q.RowsAffected), q.Error
}