1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-21 23:32:27 +00:00

Fixed: Display last/next monitored albums for artists

This commit is contained in:
Bogdan 2024-07-14 19:28:28 +03:00
parent eb04673040
commit a52c6f6f41
8 changed files with 17 additions and 18 deletions

View file

@ -10,6 +10,7 @@ export interface Statistics {
}
interface Album extends ModelBase {
artistId: number;
artist: Artist;
foreignAlbumId: string;
title: string;

View file

@ -4,10 +4,11 @@ import Link from 'Components/Link/Link';
function AlbumTitleLink({ foreignAlbumId, title, disambiguation }) {
const link = `/album/${foreignAlbumId}`;
const albumTitle = `${title}${disambiguation ? ` (${disambiguation})` : ''}`;
return (
<Link to={link}>
{title}{disambiguation ? ` (${disambiguation})` : ''}
<Link to={link} title={albumTitle}>
{albumTitle}
</Link>
);
}

View file

@ -23,7 +23,6 @@ export interface Ratings {
interface Artist extends ModelBase {
added: string;
artistMetadataId: string;
foreignArtistId: string;
cleanName: string;
ended: boolean;

View file

@ -11,7 +11,7 @@ function createArtistAlbumsSelector(artistId: number) {
const { isFetching, isPopulated, error, items } = albums;
const filteredAlbums = items.filter(
(album) => album.artist.artistMetadataId === artist.artistMetadataId
(album) => album.artistId === artist.id
);
return {

View file

@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using Lidarr.Api.V1.Albums;
using Lidarr.Http.REST;
using Newtonsoft.Json;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.MediaCover;
using NzbDrone.Core.Music;
@ -32,7 +32,10 @@ public class ArtistResource : RestResource
public string Disambiguation { get; set; }
public List<Links> Links { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public AlbumResource NextAlbum { get; set; }
[JsonIgnore(Condition = JsonIgnoreCondition.Never)]
public AlbumResource LastAlbum { get; set; }
public List<MediaCover> Images { get; set; }
@ -74,7 +77,6 @@ public static ArtistResource ToResource(this NzbDrone.Core.Music.Artist model)
return new ArtistResource
{
Id = model.Id,
ArtistMetadataId = model.ArtistMetadataId,
ArtistName = model.Name,

View file

@ -8670,10 +8670,6 @@
"type": "integer",
"format": "int32"
},
"artistMetadataId": {
"type": "integer",
"format": "int32"
},
"status": {
"$ref": "#/components/schemas/ArtistStatusType"
},

View file

@ -193,7 +193,7 @@ public void get_next_albums_should_return_next_album()
GivenMultipleAlbums();
var result = _albumRepo.GetNextAlbums(new[] { _artist.ArtistMetadataId });
result.Should().BeEquivalentTo(_albums.Take(1), AlbumComparerOptions);
result.Should().BeEquivalentTo(_albums.Skip(1).Take(1), AlbumComparerOptions);
}
[Test]
@ -202,7 +202,7 @@ public void get_last_albums_should_return_next_album()
GivenMultipleAlbums();
var result = _albumRepo.GetLastAlbums(new[] { _artist.ArtistMetadataId });
result.Should().BeEquivalentTo(_albums.Skip(2).Take(1), AlbumComparerOptions);
result.Should().BeEquivalentTo(_albums.Skip(3).Take(1), AlbumComparerOptions);
}
private EquivalencyAssertionOptions<Album> AlbumComparerOptions(EquivalencyAssertionOptions<Album> opts) => opts.ComparingByMembers<Album>()

View file

@ -46,13 +46,13 @@ public List<Album> GetLastAlbums(IEnumerable<int> artistMetadataIds)
var now = DateTime.UtcNow;
var inner = Builder()
.Select("MIN(\"Albums\".\"Id\") as id, MAX(\"Albums\".\"ReleaseDate\") as date")
.Where<Album>(x => artistMetadataIds.Contains(x.ArtistMetadataId) && x.ReleaseDate < now)
.Select("\"Albums\".\"ArtistMetadataId\" AS artist_metadata_id, MAX(\"Albums\".\"ReleaseDate\") AS date")
.Where<Album>(x => artistMetadataIds.Contains(x.ArtistMetadataId) && x.Monitored == true && x.ReleaseDate < now)
.GroupBy<Album>(x => x.ArtistMetadataId)
.AddSelectTemplate(typeof(Album));
var outer = Builder()
.Join($"({inner.RawSql}) ids on ids.id = \"Albums\".\"Id\" and ids.date = \"Albums\".\"ReleaseDate\"")
.Join($"({inner.RawSql}) ids ON ids.artist_metadata_id = \"Albums\".\"ArtistMetadataId\" AND ids.date = \"Albums\".\"ReleaseDate\"")
.AddParameters(inner.Parameters);
return Query(outer);
@ -63,13 +63,13 @@ public List<Album> GetNextAlbums(IEnumerable<int> artistMetadataIds)
var now = DateTime.UtcNow;
var inner = Builder()
.Select("MIN(\"Albums\".\"Id\") as id, MIN(\"Albums\".\"ReleaseDate\") as date")
.Where<Album>(x => artistMetadataIds.Contains(x.ArtistMetadataId) && x.ReleaseDate > now)
.Select("\"Albums\".\"ArtistMetadataId\" AS artist_metadata_id, MIN(\"Albums\".\"ReleaseDate\") AS date")
.Where<Album>(x => artistMetadataIds.Contains(x.ArtistMetadataId) && x.Monitored == true && x.ReleaseDate > now)
.GroupBy<Album>(x => x.ArtistMetadataId)
.AddSelectTemplate(typeof(Album));
var outer = Builder()
.Join($"({inner.RawSql}) ids on ids.id = \"Albums\".\"Id\" and ids.date = \"Albums\".\"ReleaseDate\"")
.Join($"({inner.RawSql}) ids ON ids.artist_metadata_id = \"Albums\".\"ArtistMetadataId\" AND ids.date = \"Albums\".\"ReleaseDate\"")
.AddParameters(inner.Parameters);
return Query(outer);