From 0c53a4509c6ba4ae981c82816fe4a88c2c068f05 Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Fri, 4 Feb 2022 20:17:17 -0600 Subject: [PATCH] show collection name in some error messages (#612) --- CHANGELOG.md | 1 + .../Fakes/FakeMediaCollectionRepository.cs | 1 + .../IMediaCollectionRepository.cs | 1 + ErsatzTV.Core/Scheduling/PlayoutBuilder.cs | 20 ++++++++++-- .../Repositories/MediaCollectionRepository.cs | 31 +++++++++++++++++++ 5 files changed, 51 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 660d47ab2..d7fa77f90 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Changed - Intermittent watermarks will now fade in and out +- Show collection name in some playout build error messages ## [0.4.0-alpha] - 2022-01-29 ### Fixed diff --git a/ErsatzTV.Core.Tests/Fakes/FakeMediaCollectionRepository.cs b/ErsatzTV.Core.Tests/Fakes/FakeMediaCollectionRepository.cs index a5829fdbc..697075492 100644 --- a/ErsatzTV.Core.Tests/Fakes/FakeMediaCollectionRepository.cs +++ b/ErsatzTV.Core.Tests/Fakes/FakeMediaCollectionRepository.cs @@ -37,5 +37,6 @@ namespace ErsatzTV.Core.Tests.Fakes throw new NotSupportedException(); public Task IsCustomPlaybackOrder(int collectionId) => false.AsTask(); + public Task> GetNameFromKey(CollectionKey emptyCollection) => Option.None.AsTask(); } } diff --git a/ErsatzTV.Core/Interfaces/Repositories/IMediaCollectionRepository.cs b/ErsatzTV.Core/Interfaces/Repositories/IMediaCollectionRepository.cs index cb82f0227..2e182fc60 100644 --- a/ErsatzTV.Core/Interfaces/Repositories/IMediaCollectionRepository.cs +++ b/ErsatzTV.Core/Interfaces/Repositories/IMediaCollectionRepository.cs @@ -18,5 +18,6 @@ namespace ErsatzTV.Core.Interfaces.Repositories Task> PlayoutIdsUsingMultiCollection(int multiCollectionId); Task> PlayoutIdsUsingSmartCollection(int smartCollectionId); Task IsCustomPlaybackOrder(int collectionId); + Task> GetNameFromKey(CollectionKey emptyCollection); } } diff --git a/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs b/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs index 49e564d5a..b9e5fd9db 100644 --- a/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs +++ b/ErsatzTV.Core/Scheduling/PlayoutBuilder.cs @@ -73,9 +73,23 @@ namespace ErsatzTV.Core.Scheduling Option maybeEmptyCollection = await CheckForEmptyCollections(collectionMediaItems); foreach (CollectionKey emptyCollection in maybeEmptyCollection) { - _logger.LogError( - "Unable to rebuild playout; collection {@CollectionKey} has no valid items!", - emptyCollection); + Option maybeName = await _mediaCollectionRepository.GetNameFromKey(emptyCollection); + if (maybeName.IsSome) + { + foreach (string name in maybeName) + { + _logger.LogError( + "Unable to rebuild playout; {CollectionType} {CollectionName} has no valid items!", + emptyCollection.CollectionType, + name); + } + } + else + { + _logger.LogError( + "Unable to rebuild playout; collection {@CollectionKey} has no valid items!", + emptyCollection); + } return playout; } diff --git a/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs index 526b1cf5e..10d83dbb6 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/MediaCollectionRepository.cs @@ -355,6 +355,37 @@ namespace ErsatzTV.Infrastructure.Data.Repositories @"SELECT IFNULL(MIN(UseCustomPlaybackOrder), 0) FROM Collection WHERE Id = @CollectionId", new { CollectionId = collectionId }); + public async Task> GetNameFromKey(CollectionKey emptyCollection) + { + await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); + + return emptyCollection.CollectionType switch + { + ProgramScheduleItemCollectionType.Artist => await dbContext.Artists.Include(a => a.ArtistMetadata) + .SelectOneAsync(a => a.Id, a => a.Id == emptyCollection.MediaItemId.Value) + .MapT(a => a.ArtistMetadata.Head().Title), + ProgramScheduleItemCollectionType.Collection => await dbContext.Collections + .SelectOneAsync(c => c.Id, c => c.Id == emptyCollection.CollectionId.Value) + .MapT(c => c.Name), + ProgramScheduleItemCollectionType.MultiCollection => await dbContext.MultiCollections + .SelectOneAsync(c => c.Id, c => c.Id == emptyCollection.MultiCollectionId.Value) + .MapT(c => c.Name), + ProgramScheduleItemCollectionType.SmartCollection => await dbContext.SmartCollections + .SelectOneAsync(c => c.Id, c => c.Id == emptyCollection.SmartCollectionId.Value) + .MapT(c => c.Name), + ProgramScheduleItemCollectionType.TelevisionSeason => await dbContext.Seasons + .Include(s => s.SeasonMetadata) + .Include(s => s.Show) + .ThenInclude(s => s.ShowMetadata) + .SelectOneAsync(a => a.Id, a => a.Id == emptyCollection.MediaItemId.Value) + .MapT(s => $"{s.Show.ShowMetadata.Head().Title} Season {s.SeasonNumber}"), + ProgramScheduleItemCollectionType.TelevisionShow => await dbContext.Shows.Include(s => s.ShowMetadata) + .SelectOneAsync(a => a.Id, a => a.Id == emptyCollection.MediaItemId.Value) + .MapT(s => s.ShowMetadata.Head().Title), + _ => None + }; + } + private async Task> GetMovieItems(TvContext dbContext, int collectionId) { IEnumerable ids = await _dbConnection.QueryAsync(