From f7f6ad159c2b5e78f23a6dfbba4cd1ad5b39308b Mon Sep 17 00:00:00 2001 From: Qstick Date: Sat, 25 Nov 2017 00:16:46 -0500 Subject: [PATCH] Temp Fix for Calendar Feed until Data Mapper can be fixed. --- .../Calendar/CalendarFeedModule.cs | 11 +++++---- .../Datastore/MarrDataLazyLoadingFixture.cs | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/Lidarr.Api.V1/Calendar/CalendarFeedModule.cs b/src/Lidarr.Api.V1/Calendar/CalendarFeedModule.cs index b2493437c..75ced18e4 100644 --- a/src/Lidarr.Api.V1/Calendar/CalendarFeedModule.cs +++ b/src/Lidarr.Api.V1/Calendar/CalendarFeedModule.cs @@ -19,12 +19,14 @@ namespace Lidarr.Api.V1.Calendar public class CalendarFeedModule : LidarrV1FeedModule { private readonly IAlbumService _albumService; + private readonly IArtistService _artistService; private readonly ITagService _tagService; - public CalendarFeedModule(IAlbumService albumService, ITagService tagService) + public CalendarFeedModule(IAlbumService albumService, IArtistService artistService, ITagService tagService) : base("calendar") { _albumService = albumService; + _artistService = artistService; _tagService = tagService; Get["/Lidarr.ics"] = options => GetCalendarFeed(); @@ -37,7 +39,6 @@ namespace Lidarr.Api.V1.Calendar var start = DateTime.Today.AddDays(-pastDays); var end = DateTime.Today.AddDays(futureDays); var unmonitored = Request.GetBooleanQueryParameter("unmonitored"); - var asAllDay = Request.GetBooleanQueryParameter("asAllDay"); var tags = new List(); var queryPastDays = Request.Query.PastDays; @@ -74,7 +75,9 @@ namespace Lidarr.Api.V1.Calendar foreach (var album in albums.OrderBy(v => v.ReleaseDate.Value)) { - if (tags.Any() && tags.None(album.Artist.Tags.Contains)) + var artist = _artistService.GetArtist(album.ArtistId); // Temp fix TODO: Figure out why Album.Artist is not populated during AlbumsBetweenDates Query + + if (tags.Any() && tags.None(artist.Tags.Contains)) { continue; } @@ -87,7 +90,7 @@ namespace Lidarr.Api.V1.Calendar occurrence.Start = new CalDateTime(album.ReleaseDate.Value.ToLocalTime()) { HasTime = false }; - occurrence.Summary = $"{album.Artist.Name} - {album.Title}"; + occurrence.Summary = $"{artist.Name} - {album.Title}"; } var serializer = (IStringSerializer)new SerializerFactory().Build(calendar.GetType(), new SerializationContext()); diff --git a/src/NzbDrone.Core.Test/Datastore/MarrDataLazyLoadingFixture.cs b/src/NzbDrone.Core.Test/Datastore/MarrDataLazyLoadingFixture.cs index 0bda7e67f..463307079 100644 --- a/src/NzbDrone.Core.Test/Datastore/MarrDataLazyLoadingFixture.cs +++ b/src/NzbDrone.Core.Test/Datastore/MarrDataLazyLoadingFixture.cs @@ -46,6 +46,13 @@ namespace NzbDrone.Core.Test.Datastore Db.InsertMany(artist); + var albums = Builder.CreateListOfSize(3) + .All() + .With(v => v.ArtistId = artist[0].Id) + .BuildListOfNew(); + + Db.InsertMany(albums); + var trackFiles = Builder.CreateListOfSize(1) .All() .With(v => v.ArtistId = artist[0].Id) @@ -64,6 +71,22 @@ namespace NzbDrone.Core.Test.Datastore Db.InsertMany(tracks); } + [Test] + public void should_join_artist_when_query_for_albums() + { + var db = Mocker.Resolve(); + var DataMapper = db.GetDataMapper(); + + var albums = DataMapper.Query() + .Join(Marr.Data.QGen.JoinType.Inner, v => v.Artist, (l, r) => l.ArtistId == r.Id) + .ToList(); + + foreach (var album in albums) + { + Assert.IsNotNull(album.Artist); + } + } + [Test] public void should_lazy_load_profile_if_not_joined() {