mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-17 22:43:07 +03:00
de-normalize item by name data. create counts during library scan for fast access.
This commit is contained in:
@@ -22,28 +22,6 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Class GetArtistsItemCounts
|
||||
/// </summary>
|
||||
[Route("/Artists/{Name}/Counts", "GET")]
|
||||
[Api(Description = "Gets item counts of library items that an artist appears in")]
|
||||
public class GetArtistsItemCounts : IReturn<ItemByNameCounts>
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the user id.
|
||||
/// </summary>
|
||||
/// <value>The user id.</value>
|
||||
[ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the name.
|
||||
/// </summary>
|
||||
/// <value>The name.</value>
|
||||
[ApiMember(Name = "Name", Description = "The artist name", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
|
||||
public string Name { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Artists/{Name}", "GET")]
|
||||
[Api(Description = "Gets an artist, by name")]
|
||||
public class GetArtist : IReturn<BaseItemDto>
|
||||
@@ -114,49 +92,6 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return await DtoService.GetBaseItemDto(item, fields.ToList()).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>System.Object.</returns>
|
||||
public object Get(GetArtistsItemCounts request)
|
||||
{
|
||||
var name = DeSlugArtistName(request.Name, LibraryManager);
|
||||
|
||||
var items = GetItems(request.UserId).Where(i =>
|
||||
{
|
||||
var song = i as Audio;
|
||||
|
||||
if (song != null)
|
||||
{
|
||||
return song.HasArtist(name);
|
||||
}
|
||||
|
||||
var musicVideo = i as MusicVideo;
|
||||
|
||||
if (musicVideo != null)
|
||||
{
|
||||
return musicVideo.HasArtist(name);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}).ToList();
|
||||
|
||||
var counts = new ItemByNameCounts
|
||||
{
|
||||
TotalCount = items.Count,
|
||||
|
||||
SongCount = items.OfType<Audio>().Count(),
|
||||
|
||||
AlbumCount = items.Select(i => i.Parent).OfType<MusicAlbum>().Distinct().Count(),
|
||||
|
||||
MusicVideoCount = items.OfType<MusicVideo>().Count(i => i.HasArtist(name))
|
||||
};
|
||||
|
||||
return ToOptimizedResult(counts);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified request.
|
||||
/// </summary>
|
||||
@@ -193,7 +128,7 @@ namespace MediaBrowser.Api.UserLibrary
|
||||
return list;
|
||||
})
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.Select(name => new IbnStub<Artist>(name, () => itemsList.Where(i => i.HasArtist(name)), GetEntity));
|
||||
.Select(name => new IbnStub<Artist>(name, GetEntity));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user