1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-21 23:32:27 +00:00

Fixed: Loading queue with pending releases for deleted artists

(cherry picked from commit 38c0135d7cd05b22bede934f8571c439dcf70a88)

Closes #5214
This commit is contained in:
Bogdan 2024-10-31 17:16:33 +02:00
parent 29d17c6347
commit 3f81e0254f
3 changed files with 18 additions and 10 deletions

View file

@ -64,19 +64,25 @@ public static SqlBuilder OrWhere<TModel>(this SqlBuilder builder, Expression<Fun
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 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)
{
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<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));
return builder.InnerJoin($"\"{rightTable}\" ON {wb}");
}
public static SqlBuilder GroupBy<TModel>(this SqlBuilder builder, Expression<Func<TModel, object>> property)

View file

@ -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<PendingRelease> AllByArtistId(int artistId)
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);
}
}
}

View file

@ -273,10 +273,7 @@ private List<PendingRelease> IncludeRemoteAlbums(List<PendingRelease> 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<PendingRelease> IncludeRemoteAlbums(List<PendingRelease> 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