Improve Load Time of Artist Detail Page, and Wanted Page

pull/94/head
Qstick 7 years ago
parent 1700c471b7
commit a37be66f34

@ -98,12 +98,9 @@ namespace Lidarr.Api.V3.Albums
}
}
for (var i = 0; i < albums.Count; i++)
{
var resource = result[i];
FetchAndLinkAlbumStatistics(resource);
}
var artistList = albums.DistinctBy(a => a.ArtistId).ToList();
var artistStats = _artistStatisticsService.ArtistStatistics();
LinkArtistStatistics(result, artistStats);
return result;
}
@ -113,6 +110,15 @@ namespace Lidarr.Api.V3.Albums
LinkArtistStatistics(resource, _artistStatisticsService.ArtistStatistics(resource.ArtistId));
}
private void LinkArtistStatistics(List<AlbumResource> resources, List<ArtistStatistics> artistStatistics)
{
foreach (var album in resources)
{
var stats = artistStatistics.SingleOrDefault(ss => ss.ArtistId == album.ArtistId);
LinkArtistStatistics(album, stats);
}
}
private void LinkArtistStatistics(AlbumResource resource, ArtistStatistics artistStatistics)
{
if (artistStatistics.AlbumStatistics != null)

@ -31,7 +31,7 @@ namespace Lidarr.Api.V3.Wanted
SortDirection = pagingResource.SortDirection
};
var includeArtist = Request.GetBooleanQueryParameter("includeSeries");
var includeArtist = Request.GetBooleanQueryParameter("includeArtist");
if (pagingResource.FilterKey == "monitored" && pagingResource.FilterValue == "false")
{

@ -80,29 +80,33 @@ namespace NzbDrone.Core.Music
private QueryBuilder<Album> GetMissingAlbumsQuery(PagingSpec<Album> pagingSpec, DateTime currentTime)
{
string sortKey;
string monitored = "([t0].[Monitored] = 0) OR ([t1].[Monitored] = 0)";
string monitored = "(Albums.[Monitored] = 0) OR (Artists.[Monitored] = 0)";
if (pagingSpec.FilterExpression.ToString().Contains("True"))
{
monitored = "([t0].[Monitored] = 1) AND ([t1].[Monitored] = 1)";
monitored = "(Albums.[Monitored] = 1) AND (Artists.[Monitored] = 1)";
}
if (pagingSpec.SortKey == "releaseDate")
{
sortKey = "[t0]." + pagingSpec.SortKey;
sortKey = "Albums." + pagingSpec.SortKey;
}
else if (pagingSpec.SortKey == "artist.sortName")
{
sortKey = "[t1]." + pagingSpec.SortKey.Split('.').Last();
sortKey = "Artists." + pagingSpec.SortKey.Split('.').Last();
}
else
{
sortKey = "[t0].releaseDate";
sortKey = "Albums.releaseDate";
}
string query = string.Format("SELECT * FROM Albums [t0] INNER JOIN Artists [t1] ON ([t0].[ArtistId] = [t1].[Id])" +
"WHERE ({0}) AND {1}" +
" AND NOT EXISTS (SELECT 1 from Tracks [t2] WHERE [t2].albumId = [t0].id AND [t2].trackFileId <> 0) ORDER BY {2} {3} LIMIT {4} OFFSET {5}",
string query = string.Format("SELECT Albums.* FROM (SELECT Tracks.AlbumId, COUNT(*) AS TotalTrackCount," + "" +
"SUM(CASE WHEN TrackFileId > 0 THEN 1 ELSE 0 END) AS AvailableTrackCount FROM Tracks GROUP BY Tracks.ArtistId, Tracks.AlbumId) as Tracks" +
" LEFT OUTER JOIN Albums ON Tracks.AlbumId == Albums.Id" +
" LEFT OUTER JOIN Artists ON Albums.ArtistId == Artists.Id" +
" WHERE Tracks.TotalTrackCount != Tracks.AvailableTrackCount AND ({0}) AND {1}" +
" GROUP BY Tracks.AlbumId" +
" ORDER BY {2} {3} LIMIT {4} OFFSET {5}",
monitored, BuildReleaseDateCutoffWhereClause(currentTime), sortKey, pagingSpec.ToSortDirection(), pagingSpec.PageSize, pagingSpec.PagingOffset());
return Query.QueryText(query);
@ -127,9 +131,12 @@ namespace NzbDrone.Core.Music
monitored = 1;
}
string query = string.Format("SELECT * FROM Albums [t0] INNER JOIN Artists [t1] ON ([t0].[ArtistId] = [t1].[Id])" +
"WHERE (([t0].[Monitored] = {0}) AND ([t1].[Monitored] = {0})) AND {1}" +
" AND NOT EXISTS (SELECT 1 from Tracks [t2] WHERE [t2].albumId = [t0].id AND [t2].trackFileId <> 0)",
string query = string.Format("SELECT Albums.* FROM (SELECT Tracks.AlbumId, COUNT(*) AS TotalTrackCount," +
" SUM(CASE WHEN TrackFileId > 0 THEN 1 ELSE 0 END) AS AvailableTrackCount FROM Tracks GROUP BY Tracks.ArtistId, Tracks.AlbumId) as Tracks" +
" LEFT OUTER JOIN Albums ON Tracks.AlbumId == Albums.Id" +
" LEFT OUTER JOIN Artists ON Albums.ArtistId == Artists.Id" +
" WHERE Tracks.TotalTrackCount != Tracks.AvailableTrackCount AND ({0}) AND {1}" +
" GROUP BY Tracks.AlbumId",
monitored, BuildReleaseDateCutoffWhereClause(currentTime));
return Query.QueryText(query).Count();
@ -137,7 +144,7 @@ namespace NzbDrone.Core.Music
private string BuildReleaseDateCutoffWhereClause(DateTime currentTime)
{
return string.Format("datetime(strftime('%s', [t0].[ReleaseDate]), 'unixepoch') <= '{0}'",
return string.Format("datetime(strftime('%s', Albums.[ReleaseDate]), 'unixepoch') <= '{0}'",
currentTime.ToString("yyyy-MM-dd HH:mm:ss"));
}

Loading…
Cancel
Save