From 38c0135d7cd05b22bede934f8571c439dcf70a88 Mon Sep 17 00:00:00 2001 From: Bogdan Date: Thu, 31 Oct 2024 17:16:33 +0200 Subject: [PATCH] Fixed: Loading queue with pending releases for deleted series --- .../Datastore/Extensions/BuilderExtensions.cs | 14 ++++++++++---- .../Download/Pending/PendingReleaseRepository.cs | 7 ++++++- .../Download/Pending/PendingReleaseService.cs | 7 ++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs b/src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs index 3bff36b7a..66dd34adc 100644 --- a/src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs +++ b/src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs @@ -64,19 +64,25 @@ public static SqlBuilder OrWhere(this SqlBuilder builder, Expression(this SqlBuilder builder, Expression> filter) { var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence); - var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight)); - return builder.Join($"\"{rightTable}\" ON {wb.ToString()}"); + return builder.Join($"\"{rightTable}\" ON {wb}"); } public static SqlBuilder LeftJoin(this SqlBuilder builder, Expression> filter) { var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence); - var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight)); - return builder.LeftJoin($"\"{rightTable}\" ON {wb.ToString()}"); + return builder.LeftJoin($"\"{rightTable}\" ON {wb}"); + } + + public static SqlBuilder InnerJoin(this SqlBuilder builder, Expression> filter) + { + var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence); + var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight)); + + return builder.InnerJoin($"\"{rightTable}\" ON {wb}"); } public static SqlBuilder GroupBy(this SqlBuilder builder, Expression> property) diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseRepository.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseRepository.cs index 5545a2f52..1db5cf5a7 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseRepository.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseRepository.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using NzbDrone.Core.Datastore; using NzbDrone.Core.Messaging.Events; +using NzbDrone.Core.Tv; namespace NzbDrone.Core.Download.Pending { @@ -30,7 +31,11 @@ public List AllBySeriesId(int seriesId) public List WithoutFallback() { - return Query(p => p.Reason != PendingReleaseReason.Fallback); + var builder = new SqlBuilder(_database.DatabaseType) + .InnerJoin((p, s) => p.SeriesId == s.Id) + .Where(p => p.Reason != PendingReleaseReason.Fallback); + + return Query(builder); } } } diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index 624dbdf46..8b6592f73 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -274,10 +274,7 @@ private List IncludeRemoteEpisodes(List releases { foreach (var series in knownRemoteEpisodes.Values.Select(v => v.Series)) { - if (!seriesMap.ContainsKey(series.Id)) - { - seriesMap[series.Id] = series; - } + seriesMap.TryAdd(series.Id, series); } } @@ -293,7 +290,7 @@ private List IncludeRemoteEpisodes(List releases // Just in case the series was removed, but wasn't cleaned up yet (housekeeper will clean it up) if (series == null) { - return null; + continue; } // Languages will be empty if added before upgrading to v4, reparsing the languages if they're empty will set it to Unknown or better.