diff --git a/src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs b/src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs index 3bff36b7a8..66dd34adc8 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}"); + } + 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.LeftJoin($"\"{rightTable}\" ON {wb.ToString()}"); + 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 9fb8d86bc6..9c88211d2e 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 f41cae0d41..334a5e2b60 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