From d8a51b5d6d7a8a78fc2f31c4e82d513f73a43a78 Mon Sep 17 00:00:00 2001 From: Jason Dove <1695733+jasongdove@users.noreply.github.com> Date: Mon, 20 Nov 2023 21:17:11 -0600 Subject: [PATCH] fix season display bug (#1511) --- CHANGELOG.md | 1 + .../Data/Repositories/TelevisionRepository.cs | 45 +++++++++++-------- 2 files changed, 28 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 70a76580..bcc1990a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Fix scanning Jellyfin libraries when library options and/or path infos are not returned from Jellyfin API - Fix error indexing music videos in `File Not Found` state - Fix bug scheduling duration filler when filler collection contains item with zero duration +- Fix bug displaying television seasons for shows that have no year metadata ### Changed - Upgrade ffmpeg to 6.1, which is now *required* for all installs diff --git a/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs b/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs index f861019f..4a39e97b 100644 --- a/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs +++ b/ErsatzTV.Infrastructure/Data/Repositories/TelevisionRepository.cs @@ -4,6 +4,7 @@ using ErsatzTV.Core.Domain; using ErsatzTV.Core.Errors; using ErsatzTV.Core.Interfaces.Repositories; using ErsatzTV.Core.Metadata; +using ErsatzTV.Infrastructure.Extensions; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -173,27 +174,35 @@ public class TelevisionRepository : ITelevisionRepository public async Task> GetPagedSeasons(int televisionShowId, int pageNumber, int pageSize) { + var result = new List(); + await using TvContext dbContext = await _dbContextFactory.CreateDbContextAsync(); - List showIds = await dbContext.Connection.QueryAsync( - @"SELECT m1.ShowId - FROM ShowMetadata m1 - LEFT OUTER JOIN ShowMetadata m2 ON m2.ShowId = @ShowId - WHERE m1.Title = m2.Title AND m1.Year = m2.Year", - new { ShowId = televisionShowId }) - .Map(results => results.ToList()); + Option maybeShowMetadata = await dbContext.ShowMetadata + .SelectOneAsync(sm => sm.Id, sm => sm.ShowId == televisionShowId); - return await dbContext.Seasons - .AsNoTracking() - .Where(s => showIds.Contains(s.ShowId)) - .Include(s => s.SeasonMetadata) - .ThenInclude(sm => sm.Artwork) - .Include(s => s.Show) - .ThenInclude(s => s.ShowMetadata) - .OrderBy(s => s.SeasonNumber) - .Skip((pageNumber - 1) * pageSize) - .Take(pageSize) - .ToListAsync(); + foreach (ShowMetadata showMetadata in maybeShowMetadata) + { + List showIds = await dbContext.ShowMetadata + .Filter(sm => sm.Title == showMetadata.Title && sm.Year == showMetadata.Year) + .Map(sm => sm.ShowId) + .ToListAsync(); + + result.AddRange( + await dbContext.Seasons + .AsNoTracking() + .Where(s => showIds.Contains(s.ShowId)) + .Include(s => s.SeasonMetadata) + .ThenInclude(sm => sm.Artwork) + .Include(s => s.Show) + .ThenInclude(s => s.ShowMetadata) + .OrderBy(s => s.SeasonNumber) + .Skip((pageNumber - 1) * pageSize) + .Take(pageSize) + .ToListAsync()); + } + + return result; } public async Task GetEpisodeCount(int seasonId)