Don't override media annotations when scanning/importing

This commit is contained in:
Deluan 2020-01-18 21:45:44 -05:00
parent 938a92eded
commit fe058aa4a1
9 changed files with 18 additions and 11 deletions

View file

@ -42,7 +42,7 @@ type MediaFiles []MediaFile
type MediaFileRepository interface {
CountAll() (int64, error)
Exists(id string) (bool, error)
Put(m *MediaFile) error
Put(m *MediaFile, overrideAnnotation bool) error
Get(id string) (*MediaFile, error)
FindByAlbum(albumId string) (MediaFiles, error)
FindByPath(path string) (MediaFiles, error)

View file

@ -140,8 +140,9 @@ group by album_id order by f.id`, strings.Join(ids, "','"))
}
if len(toUpdate) > 0 {
for _, al := range toUpdate {
_, err := o.Update(&al, "name", "artist_id", "cover_art_path", "cover_art_id", "artist", "album_artist", "year",
"compilation", "play_count", "song_count", "duration", "updated_at")
// Don't update Starred/Rating
_, err := o.Update(&al, "name", "artist_id", "cover_art_path", "cover_art_id", "artist", "album_artist",
"year", "compilation", "play_count", "play_date", "song_count", "duration", "updated_at", "created_at")
if err != nil {
return err
}

View file

@ -145,7 +145,8 @@ where f.artist_id in ('%s') group by f.artist_id order by f.id`, strings.Join(id
}
if len(toUpdate) > 0 {
for _, al := range toUpdate {
_, err := o.Update(&al)
// Don't update Starred
_, err := o.Update(&al, "name", "album_count")
if err != nil {
return err
}

View file

@ -47,9 +47,15 @@ func NewMediaFileRepository() model.MediaFileRepository {
return r
}
func (r *mediaFileRepository) Put(m *model.MediaFile) error {
func (r *mediaFileRepository) Put(m *model.MediaFile, overrideAnnotation bool) error {
tm := mediaFile(*m)
return withTx(func(o orm.Ormer) error {
if !overrideAnnotation {
// Don't update media annotation fields (playcount, starred, etc..)
return r.put(o, m.ID, m.Title, &tm, "path", "title", "album", "artist", "artist_id", "album_artist",
"album_id", "has_cover_art", "track_number", "disc_number", "year", "size", "suffix", "duration",
"bit_rate", "genre", "compilation", "updated_at")
}
return r.put(o, m.ID, m.Title, &tm)
})
}

View file

@ -19,7 +19,6 @@ var _ = Describe("MediaFileRepository", func() {
Describe("FindByPath", func() {
It("returns all records from a given ArtistID", func() {
path := string(os.PathSeparator) + filepath.Join("beatles", "1")
println("Searching path", path) // TODO Remove
Expect(repo.FindByPath(path)).To(Equal(model.MediaFiles{
songComeTogether,
}))

View file

@ -71,7 +71,7 @@ var _ = Describe("Initialize test DB", func() {
}
mediaFileRepository := NewMediaFileRepository()
for _, s := range testSongs {
err := mediaFileRepository.Put(&s)
err := mediaFileRepository.Put(&s, true)
if err != nil {
panic(err)
}

View file

@ -29,7 +29,7 @@ func (r *searchableRepository) DeleteAll() error {
})
}
func (r *searchableRepository) put(o orm.Ormer, id string, textToIndex string, a interface{}) error {
func (r *searchableRepository) put(o orm.Ormer, id string, textToIndex string, a interface{}, fields ...string) error {
c, err := r.newQuery(o).Filter("id", id).Count()
if err != nil {
return err
@ -40,7 +40,7 @@ func (r *searchableRepository) put(o orm.Ormer, id string, textToIndex string, a
err = nil
}
} else {
_, err = o.Update(a)
_, err = o.Update(a, fields...)
}
if err != nil {
return err

View file

@ -169,7 +169,7 @@ func (s *TagScanner) processChangedDir(dir string, updatedArtists map[string]boo
for _, n := range newTracks {
c, ok := currentTracks[n.ID]
if !ok || (ok && n.UpdatedAt.After(c.UpdatedAt)) {
err := s.repos.mediaFile.Put(&n)
err := s.repos.mediaFile.Put(&n, false)
updatedArtists[n.ArtistID] = true
updatedAlbums[n.AlbumID] = true
numUpdatedTracks++

View file

@ -179,7 +179,7 @@ func (i *Importer) importMediaFiles() (model.MediaFiles, int) {
mf.StarredAt = original.StarredAt
}
}
if err := i.mfRepo.Put(mf); err != nil {
if err := i.mfRepo.Put(mf, true); err != nil {
log.Error(err)
}
updates++