diff --git a/src/NzbDrone.Core/Books/Model/Book.cs b/src/NzbDrone.Core/Books/Model/Book.cs index 0cd369f71..8c05c2d68 100644 --- a/src/NzbDrone.Core/Books/Model/Book.cs +++ b/src/NzbDrone.Core/Books/Model/Book.cs @@ -34,6 +34,7 @@ namespace NzbDrone.Core.Books public List Genres { get; set; } public List RelatedBooks { get; set; } public Ratings Ratings { get; set; } + public DateTime? LastSearchTime { get; set; } // These are Readarr generated/config public string CleanTitle { get; set; } diff --git a/src/NzbDrone.Core/Books/Services/BookService.cs b/src/NzbDrone.Core/Books/Services/BookService.cs index 3a0946aef..d68384340 100644 --- a/src/NzbDrone.Core/Books/Services/BookService.cs +++ b/src/NzbDrone.Core/Books/Services/BookService.cs @@ -31,6 +31,7 @@ namespace NzbDrone.Core.Books Book UpdateBook(Book book); void SetBookMonitored(int bookId, bool monitored); void SetMonitored(IEnumerable ids, bool monitored); + void UpdateLastSearchTime(List books); PagingSpec BooksWithoutFiles(PagingSpec pagingSpec); List BooksBetweenDates(DateTime start, DateTime end, bool includeUnmonitored); List AuthorBooksBetweenDates(Author author, DateTime start, DateTime end, bool includeUnmonitored); @@ -303,6 +304,11 @@ namespace NzbDrone.Core.Books } } + public void UpdateLastSearchTime(List books) + { + _bookRepository.SetFields(books, b => b.LastSearchTime); + } + public void Handle(AuthorDeletedEvent message) { var books = GetBooksByAuthorMetadataId(message.Author.AuthorMetadataId); diff --git a/src/NzbDrone.Core/Datastore/Migration/039_book_last_searched_time.cs b/src/NzbDrone.Core/Datastore/Migration/039_book_last_searched_time.cs new file mode 100644 index 000000000..d8f55f79c --- /dev/null +++ b/src/NzbDrone.Core/Datastore/Migration/039_book_last_searched_time.cs @@ -0,0 +1,14 @@ +using FluentMigrator; +using NzbDrone.Core.Datastore.Migration.Framework; + +namespace NzbDrone.Core.Datastore.Migration +{ + [Migration(039)] + public class book_last_searched_time : NzbDroneMigrationBase + { + protected override void MainDbUpgrade() + { + Alter.Table("Books").AddColumn("LastSearchTime").AsDateTimeOffset().Nullable(); + } + } +} diff --git a/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs b/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs index dc4844bb9..523d661ed 100644 --- a/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs +++ b/src/NzbDrone.Core/IndexerSearch/ReleaseSearchService.cs @@ -136,6 +136,16 @@ namespace NzbDrone.Core.IndexerSearch _logger.Debug("Total of {0} reports were found for {1} from {2} indexers", reports.Count, criteriaBase, indexers.Count); + // Update the last search time for all albums if at least 1 indexer was searched. + if (indexers.Any()) + { + var lastSearchTime = DateTime.UtcNow; + _logger.Debug("Setting last search time to: {0}", lastSearchTime); + + criteriaBase.Books.ForEach(a => a.LastSearchTime = lastSearchTime); + _bookService.UpdateLastSearchTime(criteriaBase.Books); + } + return _makeDownloadDecision.GetSearchDecision(reports, criteriaBase).ToList(); }