mirror of
https://github.com/navidrome/navidrome.git
synced 2025-04-14 11:17:19 +03:00
Purge empty albums/artists
This commit is contained in:
parent
ea9ed4a287
commit
54d13d2022
@ -38,4 +38,5 @@ type AlbumRepository interface {
|
||||
GetStarred(...QueryOptions) (Albums, error)
|
||||
Search(q string, offset int, size int) (Albums, error)
|
||||
Refresh(ids ...string) error
|
||||
PurgeEmpty() error
|
||||
}
|
||||
|
@ -22,4 +22,5 @@ type ArtistRepository interface {
|
||||
Search(q string, offset int, size int) (Artists, error)
|
||||
Refresh(ids ...string) error
|
||||
GetIndex() (ArtistIndexes, error)
|
||||
PurgeEmpty() error
|
||||
}
|
||||
|
@ -157,6 +157,12 @@ func (r *albumRepository) PurgeInactive(activeList model.Albums) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (r *albumRepository) PurgeEmpty() error {
|
||||
o := Db()
|
||||
_, err := o.Raw("delete from album where id not in (select distinct(album_id) from media_file)").Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *albumRepository) GetStarred(options ...model.QueryOptions) (model.Albums, error) {
|
||||
var starred []album
|
||||
_, err := r.newQuery(Db(), options...).Filter("starred", true).All(&starred)
|
||||
|
@ -160,6 +160,12 @@ func (r *artistRepository) PurgeInactive(activeList model.Artists) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (r *artistRepository) PurgeEmpty() error {
|
||||
o := Db()
|
||||
_, err := o.Raw("delete from artist where id not in (select distinct(artist_id) from album)").Exec()
|
||||
return err
|
||||
}
|
||||
|
||||
func (r *artistRepository) Search(q string, offset int, size int) (model.Artists, error) {
|
||||
if len(q) <= 2 {
|
||||
return nil, nil
|
||||
|
@ -80,6 +80,16 @@ func (s *TagScanner) Scan(ctx context.Context, lastModifiedSince time.Time) erro
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.repos.album.PurgeEmpty()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.repos.artist.PurgeEmpty()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user