diff --git a/frontend/src/Store/Actions/bookActions.js b/frontend/src/Store/Actions/bookActions.js index 8b4b7ee30..a441a3a8b 100644 --- a/frontend/src/Store/Actions/bookActions.js +++ b/frontend/src/Store/Actions/bookActions.js @@ -160,7 +160,7 @@ export const sortPredicates = { status: function(item) { let result = 0; - const hasBookFile = !!item.statistics.bookFileCount; + const hasBookFile = !!item.statistics?.bookFileCount; const isAvailable = Date.parse(item.releaseDate) < new Date(); if (isAvailable) { diff --git a/src/NzbDrone.Core/AuthorStats/AuthorStatisticsRepository.cs b/src/NzbDrone.Core/AuthorStats/AuthorStatisticsRepository.cs index dca9cb9aa..bbc099961 100644 --- a/src/NzbDrone.Core/AuthorStats/AuthorStatisticsRepository.cs +++ b/src/NzbDrone.Core/AuthorStats/AuthorStatisticsRepository.cs @@ -27,22 +27,12 @@ namespace NzbDrone.Core.AuthorStats public List AuthorStatistics() { - var time = DateTime.UtcNow; - -#pragma warning disable CS0472 - return Query(Builder().OrWhere(x => x.ReleaseDate < time) - .OrWhere(x => x.Id != null)); -#pragma warning restore + return Query(Builder()); } public List AuthorStatistics(int authorId) { - var time = DateTime.UtcNow; -#pragma warning disable CS0472 - return Query(Builder().OrWhere(x => x.ReleaseDate < time) - .OrWhere(x => x.Id != null) - .Where(x => x.Id == authorId)); -#pragma warning restore + return Query(Builder().Where(x => x.Id == authorId)); } private List Query(SqlBuilder builder) @@ -61,13 +51,14 @@ namespace NzbDrone.Core.AuthorStats SUM(COALESCE(BookFiles.Size, 0)) AS SizeOnDisk, 1 AS TotalBookCount, CASE WHEN BookFiles.Id IS NULL THEN 0 ELSE 1 END AS AvailableBookCount, - CASE WHEN Books.Monitored = 1 OR BookFiles.Id IS NOT NULL THEN 1 ELSE 0 END AS BookCount, + CASE WHEN (Books.Monitored = 1 AND (Books.ReleaseDate < @currentDate) OR Books.ReleaseDate IS NULL) OR BookFiles.Id IS NOT NULL THEN 1 ELSE 0 END AS BookCount, CASE WHEN BookFiles.Id IS NULL THEN 0 ELSE COUNT(BookFiles.Id) END AS BookFileCount") .Join((e, b) => e.BookId == b.Id) .Join((book, author) => book.AuthorMetadataId == author.AuthorMetadataId) .LeftJoin((t, f) => t.Id == f.EditionId) .Where(x => x.Monitored == true) .GroupBy(x => x.Id) - .GroupBy(x => x.Id); + .GroupBy(x => x.Id) + .AddParameters(new Dictionary { { "currentDate", DateTime.UtcNow } }); } }