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) {
|
func (s *MetadataService) PersistAlbum(ctx context.Context, album *metadataPb.Album, state database.MonitorState) {
|
||||||
artistID := ""
|
s.PersistAlbumForArtist(ctx, album, "", state)
|
||||||
if len(album.GetArtists()) > 0 {
|
}
|
||||||
a, err := s.artists.GetByExternalID(ctx, album.GetArtists()[0].GetArtist().GetId())
|
|
||||||
if err == nil {
|
func (s *MetadataService) PersistAlbumForArtist(ctx context.Context, album *metadataPb.Album, artistDBID string, state database.MonitorState) {
|
||||||
artistID = a.ID
|
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")
|
log.Trace().Str("album", album.GetTitle()).Msg("skipping album persist, no artist in DB")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -135,7 +140,7 @@ func (s *MetadataService) PersistAlbum(ctx context.Context, album *metadataPb.Al
|
|||||||
|
|
||||||
err := s.albums.Create(ctx, &database.Album{
|
err := s.albums.Create(ctx, &database.Album{
|
||||||
ExternalID: album.GetId(),
|
ExternalID: album.GetId(),
|
||||||
ArtistID: artistID,
|
ArtistID: artistDBID,
|
||||||
Title: album.GetTitle(),
|
Title: album.GetTitle(),
|
||||||
AlbumType: album.GetAlbumType(),
|
AlbumType: album.GetAlbumType(),
|
||||||
TotalTracks: int(album.GetTotalTracks()),
|
TotalTracks: int(album.GetTotalTracks()),
|
||||||
|
|||||||
+1
-1
@@ -126,7 +126,7 @@ func (service *MusicAgregatorService) buildAlbumsForArtist(ctx context.Context,
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, ma := range metadataAlbums {
|
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)
|
dbAlbums, err := service.metadata.GetAlbumsByArtistID(ctx, artist.ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user