From 3f81e0254f6ac7565f131f149ac2d0442e111b1f 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 artists (cherry picked from commit 38c0135d7cd05b22bede934f8571c439dcf70a88) Closes #5214 --- .../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 9fb8d86bc..9c88211d2 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.Music; namespace NzbDrone.Core.Download.Pending { @@ -30,7 +31,11 @@ public List AllByArtistId(int artistId) public List WithoutFallback() { - return Query(p => p.Reason != PendingReleaseReason.Fallback); + var builder = new SqlBuilder(_database.DatabaseType) + .InnerJoin((p, s) => p.ArtistId == 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 f41cae0d4..334a5e2b6 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -273,10 +273,7 @@ private List IncludeRemoteAlbums(List releases, { foreach (var artist in knownRemoteAlbums.Values.Select(v => v.Artist)) { - if (!artistMap.ContainsKey(artist.Id)) - { - artistMap[artist.Id] = artist; - } + artistMap.TryAdd(artist.Id, artist); } } @@ -292,7 +289,7 @@ private List IncludeRemoteAlbums(List releases, // Just in case the artist was removed, but wasn't cleaned up yet (housekeeper will clean it up) if (artist == null) { - return null; + continue; } release.RemoteAlbum = new RemoteAlbum