Skip to content

Commit

Permalink
Fixed: Loading queue with pending releases for deleted artists
Browse files Browse the repository at this point in the history
(cherry picked from commit 38c0135d7cd05b22bede934f8571c439dcf70a88)

Closes Lidarr#5214
  • Loading branch information
mynameisbogdan committed Nov 4, 2024
1 parent 29d17c6 commit 3f81e02
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
12 changes: 9 additions & 3 deletions src/NzbDrone.Core/Datastore/Extensions/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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}");
}

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.LeftJoin($"\"{rightTable}\" ON {wb.ToString()}");
return builder.InnerJoin($"\"{rightTable}\" ON {wb}");
}

public static SqlBuilder GroupBy<TModel>(this SqlBuilder builder, Expression<Func<TModel, object>> property)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
{
Expand Down Expand Up @@ -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);
}
}
}
7 changes: 2 additions & 5 deletions src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand All @@ -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
Expand Down

0 comments on commit 3f81e02

Please sign in to comment.