Fixed: Loading queue with pending releases for deleted artists

(cherry picked from commit 38c0135d7cd05b22bede934f8571c439dcf70a88)

Closes #5214
pull/5226/head
Bogdan 3 months ago
parent 29d17c6347
commit 3f81e0254f

@ -64,19 +64,25 @@ namespace NzbDrone.Core.Datastore
public static SqlBuilder Join<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter) public static SqlBuilder Join<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
{ {
var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence); var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence);
var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight)); var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight));
return builder.Join($"\"{rightTable}\" ON {wb.ToString()}"); return builder.Join($"\"{rightTable}\" ON {wb}");
} }
public static SqlBuilder LeftJoin<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter) public static SqlBuilder LeftJoin<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
{ {
var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence); 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<TLeft, TRight>(this SqlBuilder builder, Expression<Func<TLeft, TRight, bool>> filter)
{
var wb = GetWhereBuilder(builder.DatabaseType, filter, false, builder.Sequence);
var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight)); var rightTable = TableMapping.Mapper.TableNameMapping(typeof(TRight));
return builder.LeftJoin($"\"{rightTable}\" ON {wb.ToString()}"); return builder.InnerJoin($"\"{rightTable}\" ON {wb}");
} }
public static SqlBuilder GroupBy<TModel>(this SqlBuilder builder, Expression<Func<TModel, object>> property) public static SqlBuilder GroupBy<TModel>(this SqlBuilder builder, Expression<Func<TModel, object>> property)

@ -1,6 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using NzbDrone.Core.Datastore; using NzbDrone.Core.Datastore;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Music;
namespace NzbDrone.Core.Download.Pending namespace NzbDrone.Core.Download.Pending
{ {
@ -30,7 +31,11 @@ namespace NzbDrone.Core.Download.Pending
public List<PendingRelease> WithoutFallback() public List<PendingRelease> WithoutFallback()
{ {
return Query(p => p.Reason != PendingReleaseReason.Fallback); var builder = new SqlBuilder(_database.DatabaseType)
.InnerJoin<PendingRelease, Artist>((p, s) => p.ArtistId == s.Id)
.Where<PendingRelease>(p => p.Reason != PendingReleaseReason.Fallback);
return Query(builder);
} }
} }
} }

@ -273,10 +273,7 @@ namespace NzbDrone.Core.Download.Pending
{ {
foreach (var artist in knownRemoteAlbums.Values.Select(v => v.Artist)) foreach (var artist in knownRemoteAlbums.Values.Select(v => v.Artist))
{ {
if (!artistMap.ContainsKey(artist.Id)) artistMap.TryAdd(artist.Id, artist);
{
artistMap[artist.Id] = artist;
}
} }
} }
@ -292,7 +289,7 @@ namespace NzbDrone.Core.Download.Pending
// Just in case the artist was removed, but wasn't cleaned up yet (housekeeper will clean it up) // Just in case the artist was removed, but wasn't cleaned up yet (housekeeper will clean it up)
if (artist == null) if (artist == null)
{ {
return null; continue;
} }
release.RemoteAlbum = new RemoteAlbum release.RemoteAlbum = new RemoteAlbum

Loading…
Cancel
Save