mirror of https://github.com/lidarr/Lidarr
Speed up all albums endpoint
This commit is contained in:
parent
5ddac7a679
commit
dce69212fc
|
@ -29,10 +29,12 @@ namespace Lidarr.Api.V1.Albums
|
|||
IHandle<TrackImportedEvent>,
|
||||
IHandle<TrackFileDeletedEvent>
|
||||
{
|
||||
protected readonly IArtistService _artistService;
|
||||
protected readonly IReleaseService _releaseService;
|
||||
protected readonly IAddAlbumService _addAlbumService;
|
||||
|
||||
public AlbumModule(IAlbumService albumService,
|
||||
public AlbumModule(IArtistService artistService,
|
||||
IAlbumService albumService,
|
||||
IAddAlbumService addAlbumService,
|
||||
IReleaseService releaseService,
|
||||
IArtistStatisticsService artistStatisticsService,
|
||||
|
@ -44,6 +46,7 @@ namespace Lidarr.Api.V1.Albums
|
|||
|
||||
: base(albumService, artistStatisticsService, coverMapper, upgradableSpecification, signalRBroadcaster)
|
||||
{
|
||||
_artistService = artistService;
|
||||
_releaseService = releaseService;
|
||||
_addAlbumService = addAlbumService;
|
||||
|
||||
|
@ -69,7 +72,25 @@ namespace Lidarr.Api.V1.Albums
|
|||
|
||||
if (!Request.Query.ArtistId.HasValue && !albumIdsQuery.HasValue && !foreignIdQuery.HasValue)
|
||||
{
|
||||
return MapToResource(_albumService.GetAllAlbums(), false);
|
||||
var albums = _albumService.GetAllAlbums();
|
||||
|
||||
var artists = _artistService.GetAllArtists().ToDictionary(x => x.ArtistMetadataId);
|
||||
var releases = _releaseService.GetAllReleases().GroupBy(x => x.AlbumId).ToDictionary(x => x.Key, y => y.ToList());
|
||||
|
||||
foreach (var album in albums)
|
||||
{
|
||||
album.Artist = artists[album.ArtistMetadataId];
|
||||
if (releases.TryGetValue(album.Id, out var albumReleases))
|
||||
{
|
||||
album.AlbumReleases = albumReleases;
|
||||
}
|
||||
else
|
||||
{
|
||||
album.AlbumReleases = new List<AlbumRelease>();
|
||||
}
|
||||
}
|
||||
|
||||
return MapToResource(albums, false);
|
||||
}
|
||||
|
||||
if (artistIdQuery.HasValue)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NzbDrone.Core.Messaging.Events;
|
||||
using NzbDrone.Core.Music.Events;
|
||||
|
||||
|
@ -8,6 +9,7 @@ namespace NzbDrone.Core.Music
|
|||
{
|
||||
AlbumRelease GetRelease(int id);
|
||||
AlbumRelease GetReleaseByForeignReleaseId(string foreignReleaseId, bool checkRedirect = false);
|
||||
List<AlbumRelease> GetAllReleases();
|
||||
void InsertMany(List<AlbumRelease> releases);
|
||||
void UpdateMany(List<AlbumRelease> releases);
|
||||
void DeleteMany(List<AlbumRelease> releases);
|
||||
|
@ -40,6 +42,11 @@ namespace NzbDrone.Core.Music
|
|||
return _releaseRepository.FindByForeignReleaseId(foreignReleaseId, checkRedirect);
|
||||
}
|
||||
|
||||
public List<AlbumRelease> GetAllReleases()
|
||||
{
|
||||
return _releaseRepository.All().ToList();
|
||||
}
|
||||
|
||||
public void InsertMany(List<AlbumRelease> releases)
|
||||
{
|
||||
_releaseRepository.InsertMany(releases);
|
||||
|
|
Loading…
Reference in New Issue