diff --git a/CHANGELOG.md b/CHANGELOG.md index ad6219d43..815453ae0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ## [Unreleased] +### Fixed +- Fix schedule editor crashing due to bad music video artist data + ### Changed - Always use software pipeline for error display - This ensures errors will display even when hardware acceleration is misconfigured diff --git a/ErsatzTV.Application/Artists/Queries/GetAllArtistsHandler.cs b/ErsatzTV.Application/Artists/Queries/GetAllArtistsHandler.cs index 6fcc7d9da..9fc031bf3 100644 --- a/ErsatzTV.Application/Artists/Queries/GetAllArtistsHandler.cs +++ b/ErsatzTV.Application/Artists/Queries/GetAllArtistsHandler.cs @@ -1,22 +1,44 @@ using ErsatzTV.Application.MediaItems; -using ErsatzTV.Core.Interfaces.Repositories; +using ErsatzTV.Core.Domain; +using ErsatzTV.Infrastructure.Data; +using Microsoft.EntityFrameworkCore; using static ErsatzTV.Application.MediaItems.Mapper; namespace ErsatzTV.Application.Artists; public class GetAllArtistsHandler : IRequestHandler> { - private readonly IArtistRepository _artistRepository; + private readonly IDbContextFactory _dbContextFactory; - public GetAllArtistsHandler(IArtistRepository artistRepository) => _artistRepository = artistRepository; + public GetAllArtistsHandler(IDbContextFactory dbContextFactory) + { + _dbContextFactory = dbContextFactory; + } - public Task> Handle( + public async Task> Handle( GetAllArtists request, - CancellationToken cancellationToken) => - _artistRepository.GetAllArtists() - .Map( - list => list.Filter( - a => !string.IsNullOrWhiteSpace( - a.ArtistMetadata.HeadOrNone().Match(am => am.Title, () => string.Empty)))) - .Map(list => list.Map(ProjectToViewModel).ToList()); + CancellationToken cancellationToken) + { + await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(cancellationToken); + + List allArtists = await dbContext.Artists + .AsNoTracking() + .Include(a => a.ArtistMetadata) + .ToListAsync(cancellationToken: cancellationToken); + + return allArtists.Bind(a => ProjectArtist(a)).ToList(); + } + + private static Option ProjectArtist(Artist a) + { + foreach (ArtistMetadata metadata in a.ArtistMetadata.HeadOrNone()) + { + if (!string.IsNullOrWhiteSpace(metadata.Title)) + { + return ProjectToViewModel(a); + } + } + + return None; + } } diff --git a/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj b/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj index a2c59abda..f868743ff 100644 --- a/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj +++ b/ErsatzTV.Core.Tests/ErsatzTV.Core.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/ErsatzTV.Core/Interfaces/Repositories/IArtistRepository.cs b/ErsatzTV.Core/Interfaces/Repositories/IArtistRepository.cs index f4d3ca7a1..f5d0490c1 100644 --- a/ErsatzTV.Core/Interfaces/Repositories/IArtistRepository.cs +++ b/ErsatzTV.Core/Interfaces/Repositories/IArtistRepository.cs @@ -19,5 +19,4 @@ public interface IArtistRepository Task AddStyle(ArtistMetadata metadata, Style style); Task AddMood(ArtistMetadata metadata, Mood mood); Task> GetArtistItems(int artistId); - Task> GetAllArtists(); } diff --git a/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj b/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj index fea4202f7..7f0a699d3 100644 --- a/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj +++ b/ErsatzTV.FFmpeg.Tests/ErsatzTV.FFmpeg.Tests.csproj @@ -8,7 +8,7 @@ - + diff --git a/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj b/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj index 15fcab003..04fe05ec9 100644 --- a/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj +++ b/ErsatzTV.Infrastructure.Tests/ErsatzTV.Infrastructure.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/ErsatzTV.Infrastructure/Data/Repositories/ArtistRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/ArtistRepository.cs index 5f778f507..d8e333a8b 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/ArtistRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/ArtistRepository.cs @@ -160,14 +160,4 @@ public class ArtistRepository : IArtistRepository .Filter(mv => mv.ArtistId == artistId) .ToListAsync(); } - - public async Task> GetAllArtists() - { - await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); - return await dbContext.Artists - .AsNoTracking() - .Include(a => a.ArtistMetadata) - .ThenInclude(am => am.Artwork) - .ToListAsync(); - } } diff --git a/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj b/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj index fbc862481..717851498 100644 --- a/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj +++ b/ErsatzTV.Infrastructure/ErsatzTV.Infrastructure.csproj @@ -11,16 +11,16 @@ - + - - + + all runtime; build; native; contentfiles; analyzers; buildtransitive - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj b/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj index 77198db96..2fc64d23e 100644 --- a/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj +++ b/ErsatzTV.Scanner.Tests/ErsatzTV.Scanner.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/ErsatzTV/ErsatzTV.csproj b/ErsatzTV/ErsatzTV.csproj index 4a291947a..11ce00cd6 100644 --- a/ErsatzTV/ErsatzTV.csproj +++ b/ErsatzTV/ErsatzTV.csproj @@ -60,9 +60,9 @@ - - - + + + all runtime; build; native; contentfiles; analyzers; buildtransitive