From 3de5428efe116e8756a27bba30342f89d8db99b2 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 20 Dec 2022 18:28:33 -0800 Subject: [PATCH] New: Don't block imports when release was matched by ID if they were grabbed via interactive search (cherry picked from commit bc2942c28d3c48e9eea61a68baf032ba181aef1e) --- .../PendingReleaseServiceFixture.cs | 2 +- ...add_additional_info_to_pending_releases.cs | 14 +++++++++ src/NzbDrone.Core/Datastore/TableMapping.cs | 1 + .../DecisionEngine/DownloadDecisionMaker.cs | 30 +++++++++++++++---- .../Download/Pending/PendingRelease.cs | 6 ++++ .../Download/Pending/PendingReleaseService.cs | 4 +-- src/NzbDrone.Core/History/EntityHistory.cs | 1 + .../History/EntityHistoryService.cs | 1 + src/NzbDrone.Core/Parser/Model/RemoteAlbum.cs | 11 +++++++ 9 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 src/NzbDrone.Core/Datastore/Migration/067_add_additional_info_to_pending_releases.cs diff --git a/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs b/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs index 5933db2e4..1b559c46e 100644 --- a/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Download/Pending/PendingReleaseServiceTests/PendingReleaseServiceFixture.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.Download.Pending.PendingReleaseServiceTests results.Should().NotBeEmpty(); Mocker.GetMock() - .Verify(v => v.GetRssDecision(It.Is>(d => d.Count == 0)), Times.Never()); + .Verify(v => v.GetRssDecision(It.Is>(d => d.Count == 0), It.IsAny()), Times.Never()); } [Test] diff --git a/src/NzbDrone.Core/Datastore/Migration/067_add_additional_info_to_pending_releases.cs b/src/NzbDrone.Core/Datastore/Migration/067_add_additional_info_to_pending_releases.cs new file mode 100644 index 000000000..a9cd31c1e --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/067_add_additional_info_to_pending_releases.cs @@ -0,0 +1,14 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(067)] + public class add_additional_info_to_pending_releases : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("PendingReleases").AddColumn("AdditionalInfo").AsString().Nullable(); + } + } +} diff --git a/src/NzbDrone.Core/Datastore/TableMapping.cs b/src/NzbDrone.Core/Datastore/TableMapping.cs index ca9052f58..8579ccdcc 100644 --- a/src/NzbDrone.Core/Datastore/TableMapping.cs +++ b/src/NzbDrone.Core/Datastore/TableMapping.cs @@ -229,6 +229,7 @@ namespace NzbDrone.Core.Datastore SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter()); SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter()); SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter()); + SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter()); SqlMapper.AddTypeHandler(new EmbeddedDocumentConverter>()); SqlMapper.AddTypeHandler(new OsPathConverter()); SqlMapper.RemoveTypeMap(typeof(Guid)); diff --git a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs index 09dfcd5ea..8bd109641 100644 --- a/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs +++ b/src/NzbDrone.Core/DecisionEngine/DownloadDecisionMaker.cs @@ -16,7 +16,7 @@ namespace NzbDrone.Core.DecisionEngine { public interface IMakeDownloadDecision { - List GetRssDecision(List reports); + List GetRssDecision(List reports, bool pushedRelease = false); List GetSearchDecision(List reports, SearchCriteriaBase searchCriteriaBase); } @@ -41,17 +41,17 @@ namespace NzbDrone.Core.DecisionEngine _logger = logger; } - public List GetRssDecision(List reports) + public List GetRssDecision(List reports, bool pushedRelease = false) { - return GetAlbumDecisions(reports).ToList(); + return GetAlbumDecisions(reports, pushedRelease).ToList(); } public List GetSearchDecision(List reports, SearchCriteriaBase searchCriteriaBase) { - return GetAlbumDecisions(reports, searchCriteriaBase).ToList(); + return GetAlbumDecisions(reports, false, searchCriteriaBase).ToList(); } - private IEnumerable GetAlbumDecisions(List reports, SearchCriteriaBase searchCriteria = null) + private IEnumerable GetAlbumDecisions(List reports, bool pushedRelease, SearchCriteriaBase searchCriteria = null) { if (reports.Any()) { @@ -169,6 +169,26 @@ namespace NzbDrone.Core.DecisionEngine if (decision != null) { + var source = pushedRelease ? ReleaseSourceType.ReleasePush : ReleaseSourceType.Rss; + + if (searchCriteria != null) + { + if (searchCriteria.InteractiveSearch) + { + source = ReleaseSourceType.InteractiveSearch; + } + else if (searchCriteria.UserInvokedSearch) + { + source = ReleaseSourceType.UserInvokedSearch; + } + else + { + source = ReleaseSourceType.Search; + } + } + + decision.RemoteAlbum.ReleaseSource = source; + if (decision.Rejections.Any()) { _logger.Debug("Release rejected for the following reasons: {0}", string.Join(", ", decision.Rejections)); diff --git a/src/NzbDrone.Core/Download/Pending/PendingRelease.cs b/src/NzbDrone.Core/Download/Pending/PendingRelease.cs index 15a7cfefc..73d925cfb 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingRelease.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingRelease.cs @@ -12,8 +12,14 @@ namespace NzbDrone.Core.Download.Pending public ParsedAlbumInfo ParsedAlbumInfo { get; set; } public ReleaseInfo Release { get; set; } public PendingReleaseReason Reason { get; set; } + public PendingReleaseAdditionalInfo AdditionalInfo { get; set; } // Not persisted public RemoteAlbum RemoteAlbum { get; set; } } + + public class PendingReleaseAdditionalInfo + { + public ReleaseSourceType ReleaseSource { get; set; } + } } diff --git a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs index 5828664d0..fce7b1afa 100644 --- a/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs +++ b/src/NzbDrone.Core/Download/Pending/PendingReleaseService.cs @@ -300,8 +300,7 @@ namespace NzbDrone.Core.Download.Pending List albums; - RemoteAlbum knownRemoteAlbum; - if (knownRemoteAlbums != null && knownRemoteAlbums.TryGetValue(release.Release.Title, out knownRemoteAlbum)) + if (knownRemoteAlbums != null && knownRemoteAlbums.TryGetValue(release.Release.Title, out var knownRemoteAlbum)) { albums = knownRemoteAlbum.Albums; } @@ -315,6 +314,7 @@ namespace NzbDrone.Core.Download.Pending Artist = artist, Albums = albums, ParsedAlbumInfo = release.ParsedAlbumInfo, + ReleaseSource = release.AdditionalInfo?.ReleaseSource ?? ReleaseSourceType.Unknown, Release = release.Release }; diff --git a/src/NzbDrone.Core/History/EntityHistory.cs b/src/NzbDrone.Core/History/EntityHistory.cs index c9aada55e..ffc7e8e7c 100644 --- a/src/NzbDrone.Core/History/EntityHistory.cs +++ b/src/NzbDrone.Core/History/EntityHistory.cs @@ -9,6 +9,7 @@ namespace NzbDrone.Core.History public class EntityHistory : ModelBase { public const string DOWNLOAD_CLIENT = "downloadClient"; + public const string RELEASE_SOURCE = "releaseSource"; public EntityHistory() { diff --git a/src/NzbDrone.Core/History/EntityHistoryService.cs b/src/NzbDrone.Core/History/EntityHistoryService.cs index b1a028af4..66459b020 100644 --- a/src/NzbDrone.Core/History/EntityHistoryService.cs +++ b/src/NzbDrone.Core/History/EntityHistoryService.cs @@ -165,6 +165,7 @@ namespace NzbDrone.Core.History history.Data.Add("Protocol", ((int)message.Album.Release.DownloadProtocol).ToString()); history.Data.Add("DownloadForced", (!message.Album.DownloadAllowed).ToString()); history.Data.Add("CustomFormatScore", message.Album.CustomFormatScore.ToString()); + history.Data.Add("ReleaseSource", message.Album.ReleaseSource.ToString()); if (!message.Album.ParsedAlbumInfo.ReleaseHash.IsNullOrWhiteSpace()) { diff --git a/src/NzbDrone.Core/Parser/Model/RemoteAlbum.cs b/src/NzbDrone.Core/Parser/Model/RemoteAlbum.cs index d05bf094b..3df40b57e 100644 --- a/src/NzbDrone.Core/Parser/Model/RemoteAlbum.cs +++ b/src/NzbDrone.Core/Parser/Model/RemoteAlbum.cs @@ -17,6 +17,7 @@ namespace NzbDrone.Core.Parser.Model public TorrentSeedConfiguration SeedConfiguration { get; set; } public List CustomFormats { get; set; } public int CustomFormatScore { get; set; } + public ReleaseSourceType ReleaseSource { get; set; } public RemoteAlbum() { @@ -34,4 +35,14 @@ namespace NzbDrone.Core.Parser.Model return Release.Title; } } + + public enum ReleaseSourceType + { + Unknown = 0, + Rss = 1, + Search = 2, + UserInvokedSearch = 3, + InteractiveSearch = 4, + ReleasePush = 5 + } }