Move album refresh to scanner

This commit is contained in:
Deluan 2022-12-19 12:08:39 -05:00 committed by Deluan Quintão
parent 566ae93950
commit 2f90fc9bd4
5 changed files with 103 additions and 103 deletions

View file

@ -11,8 +11,6 @@ import (
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/utils"
"github.com/navidrome/navidrome/utils/slice"
)
type albumRepository struct {
@ -142,38 +140,6 @@ func (r *albumRepository) GetAllWithoutGenres(options ...model.QueryOptions) (mo
return res, err
}
func (r *albumRepository) Refresh(ids ...string) error {
chunks := utils.BreakUpStringSlice(ids, 100)
for _, chunk := range chunks {
err := r.refresh(chunk...)
if err != nil {
return err
}
}
return nil
}
func (r *albumRepository) refresh(ids ...string) error {
mfRepo := NewMediaFileRepository(r.ctx, r.ormer)
mfs, err := mfRepo.GetAll(model.QueryOptions{Filters: Eq{"album_id": ids}})
if err != nil {
return err
}
if len(mfs) == 0 {
return nil
}
grouped := slice.Group(mfs, func(m model.MediaFile) string { return m.AlbumID })
for _, songs := range grouped {
a := model.MediaFiles(songs).ToAlbum()
err := r.Put(&a)
if err != nil {
return err
}
}
return nil
}
func (r *albumRepository) purgeEmpty() error {
del := Delete(r.tableName).Where("id not in (select distinct(album_id) from media_file)")
c, err := r.executeSQL(del)