scanner: ormise clean artists
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user