Fix album persistence by passing artist DB ID directly to PersistAlbum
This commit is contained in:
@@ -110,15 +110,20 @@ func (s *MetadataService) PersistArtist(ctx context.Context, album *metadataPb.A
|
||||
}
|
||||
|
||||
func (s *MetadataService) PersistAlbum(ctx context.Context, album *metadataPb.Album, state database.MonitorState) {
|
||||
artistID := ""
|
||||
if len(album.GetArtists()) > 0 {
|
||||
a, err := s.artists.GetByExternalID(ctx, album.GetArtists()[0].GetArtist().GetId())
|
||||
if err == nil {
|
||||
artistID = a.ID
|
||||
s.PersistAlbumForArtist(ctx, album, "", state)
|
||||
}
|
||||
|
||||
func (s *MetadataService) PersistAlbumForArtist(ctx context.Context, album *metadataPb.Album, artistDBID string, state database.MonitorState) {
|
||||
if artistDBID == "" {
|
||||
if len(album.GetArtists()) > 0 {
|
||||
a, err := s.artists.GetByExternalID(ctx, album.GetArtists()[0].GetArtist().GetId())
|
||||
if err == nil {
|
||||
artistDBID = a.ID
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if artistID == "" {
|
||||
if artistDBID == "" {
|
||||
log.Trace().Str("album", album.GetTitle()).Msg("skipping album persist, no artist in DB")
|
||||
return
|
||||
}
|
||||
@@ -135,7 +140,7 @@ func (s *MetadataService) PersistAlbum(ctx context.Context, album *metadataPb.Al
|
||||
|
||||
err := s.albums.Create(ctx, &database.Album{
|
||||
ExternalID: album.GetId(),
|
||||
ArtistID: artistID,
|
||||
ArtistID: artistDBID,
|
||||
Title: album.GetTitle(),
|
||||
AlbumType: album.GetAlbumType(),
|
||||
TotalTracks: int(album.GetTotalTracks()),
|
||||
|
||||
Reference in New Issue
Block a user