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 := ""
|
||||
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 {
|
||||
artistID = a.ID
|
||||
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()),
|
||||
|
||||
+1
-1
@@ -126,7 +126,7 @@ func (service *MusicAgregatorService) buildAlbumsForArtist(ctx context.Context,
|
||||
}
|
||||
|
||||
for _, ma := range metadataAlbums {
|
||||
service.metadata.PersistAlbum(ctx, ma, database.Unmonitored)
|
||||
service.metadata.PersistAlbumForArtist(ctx, ma, artist.ID, database.Unmonitored)
|
||||
}
|
||||
|
||||
dbAlbums, err := service.metadata.GetAlbumsByArtistID(ctx, artist.ID)
|
||||
|
||||
Reference in New Issue
Block a user