From 735fceb0746a8bf476cac5d69bc5648c3a868219 Mon Sep 17 00:00:00 2001 From: ta264 Date: Thu, 9 Dec 2021 21:41:48 +0000 Subject: [PATCH] Fixed: Prevent duplicate searches on list add --- .../ImportLists/ImportListSyncService.cs | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs index 122e5bc78..dc067301f 100644 --- a/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs +++ b/src/NzbDrone.Core/ImportLists/ImportListSyncService.cs @@ -7,6 +7,7 @@ using NzbDrone.Common.Instrumentation.Extensions; using NzbDrone.Core.Books; using NzbDrone.Core.Books.Commands; using NzbDrone.Core.ImportLists.Exclusions; +using NzbDrone.Core.IndexerSearch; using NzbDrone.Core.Messaging.Commands; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.MetadataSource; @@ -201,19 +202,36 @@ namespace NzbDrone.Core.ImportLists if (!existingBook.Monitored) { _bookService.SetBookMonitored(existingBook.Id, true); + + if (importList.ShouldMonitor == ImportListMonitorType.SpecificBook) + { + _commandQueueManager.Push(new BookSearchCommand(new List { existingBook.Id })); + } } var existingAuthor = existingBook.Author.Value; + var doSearch = false; + if (importList.ShouldMonitor == ImportListMonitorType.EntireAuthor) { - _bookService.SetMonitored(existingAuthor.Books.Value.Select(x => x.Id), true); + if (existingAuthor.Books.Value.Any(x => !x.Monitored)) + { + doSearch = true; + _bookService.SetMonitored(existingAuthor.Books.Value.Select(x => x.Id), true); + } } if (!existingAuthor.Monitored) { + doSearch = true; existingAuthor.Monitored = true; _authorService.UpdateAuthor(existingAuthor); } + + if (doSearch) + { + _commandQueueManager.Push(new MissingBookSearchCommand(existingAuthor.Id)); + } } return; @@ -261,7 +279,9 @@ namespace NzbDrone.Core.ImportLists Author = toAddAuthor, AddOptions = new AddBookOptions { - SearchForNewBook = importList.ShouldSearch + // Only search for new book for existing authors + // New author searches are triggered by SearchForMissingBooks + SearchForNewBook = importList.ShouldSearch && toAddAuthor.Id > 0 } };