Refactor to pull item counts in a single query

This commit is contained in:
Cody Robibero
2025-08-11 21:03:55 -06:00
parent 5eef85f027
commit beca405ad4
14 changed files with 207 additions and 233 deletions

View File

@@ -98,24 +98,6 @@ namespace MediaBrowser.Controller.Entities.Audio
return LibraryManager.GetItemList(query);
}
public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
{
query.ArtistIds = [Id];
var counts = new TaggedItemCounts();
query.IncludeItemTypes = [BaseItemKind.MusicAlbum];
counts.AlbumCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicVideo];
counts.MusicVideoCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Audio];
counts.SongCount = LibraryManager.GetCount(query);
return counts;
}
public override int GetChildCount(User user)
{
return IsAccessedByName ? 0 : base.GetChildCount(user);

View File

@@ -73,27 +73,6 @@ namespace MediaBrowser.Controller.Entities.Audio
return LibraryManager.GetItemList(query);
}
public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
{
query.GenreIds = [Id];
var counts = new TaggedItemCounts();
query.IncludeItemTypes = [BaseItemKind.MusicAlbum];
counts.AlbumCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicArtist];
counts.ArtistCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicVideo];
counts.MusicVideoCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Audio];
counts.SongCount = LibraryManager.GetCount(query);
return counts;
}
public static string GetPath(string name)
{
return GetPath(name, true);

View File

@@ -76,37 +76,6 @@ namespace MediaBrowser.Controller.Entities
return LibraryManager.GetItemList(query);
}
public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
{
query.GenreIds = [Id];
query.ExcludeItemTypes =
[
BaseItemKind.MusicVideo,
BaseItemKind.Audio,
BaseItemKind.MusicAlbum,
BaseItemKind.MusicArtist
];
var counts = new TaggedItemCounts();
query.IncludeItemTypes = [BaseItemKind.Episode];
counts.EpisodeCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Movie];
counts.MovieCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.LiveTvProgram];
counts.ProgramCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Series];
counts.SeriesCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Trailer];
counts.TrailerCount = LibraryManager.GetCount(query);
return counts;
}
public static string GetPath(string name)
{
return GetPath(name, true);

View File

@@ -10,8 +10,6 @@ namespace MediaBrowser.Controller.Entities
public interface IItemByName
{
IReadOnlyList<BaseItem> GetTaggedItems(InternalItemsQuery query);
TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query);
}
public interface IHasDualAccess : IItemByName

View File

@@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using MediaBrowser.Controller.Providers;
using Microsoft.Extensions.Logging;
@@ -71,43 +70,6 @@ namespace MediaBrowser.Controller.Entities
return LibraryManager.GetItemList(query);
}
public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
{
query.PersonIds = [Id];
var counts = new TaggedItemCounts();
// TODO: Remove MusicAlbum and MusicArtist when the relationship between Persons and Music is removed
query.IncludeItemTypes = [BaseItemKind.MusicAlbum];
counts.AlbumCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicArtist];
counts.ArtistCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Episode];
counts.EpisodeCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Movie];
counts.MovieCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicVideo];
counts.MusicVideoCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.LiveTvProgram];
counts.ProgramCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Series];
counts.SeriesCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Audio];
counts.SongCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Trailer];
counts.TrailerCount = LibraryManager.GetCount(query);
return counts;
}
public override bool CanDelete()
{
return false;

View File

@@ -5,7 +5,6 @@
using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using Jellyfin.Extensions;
using Microsoft.Extensions.Logging;
@@ -72,42 +71,6 @@ namespace MediaBrowser.Controller.Entities
return LibraryManager.GetItemList(query);
}
public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
{
query.StudioIds = [Id];
var counts = new TaggedItemCounts();
query.IncludeItemTypes = [BaseItemKind.MusicAlbum];
counts.AlbumCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicArtist];
counts.ArtistCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Episode];
counts.EpisodeCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Movie];
counts.MovieCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicVideo];
counts.MusicVideoCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.LiveTvProgram];
counts.ProgramCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Series];
counts.SeriesCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Audio];
counts.SongCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Trailer];
counts.TrailerCount = LibraryManager.GetCount(query);
return counts;
}
public static string GetPath(string name)
{
return GetPath(name, true);

View File

@@ -1,27 +0,0 @@
#pragma warning disable CS1591
namespace MediaBrowser.Controller.Entities
{
public class TaggedItemCounts
{
public int? AlbumCount { get; set; }
public int? ArtistCount { get; set; }
public int? EpisodeCount { get; set; }
public int? MovieCount { get; set; }
public int? MusicVideoCount { get; set; }
public int? ProgramCount { get; set; }
public int? SeriesCount { get; set; }
public int? SongCount { get; set; }
public int? TrailerCount { get; set; }
public int ChildCount => (AlbumCount ?? 0) + (ArtistCount ?? 0) + (EpisodeCount ?? 0) + (MovieCount ?? 0) + (MusicVideoCount ?? 0) + (ProgramCount ?? 0) + (SeriesCount ?? 0) + (SongCount ?? 0) + (TrailerCount ?? 0);
}
}

View File

@@ -6,7 +6,6 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Controller.Entities
@@ -69,47 +68,6 @@ namespace MediaBrowser.Controller.Entities
return LibraryManager.GetItemList(query);
}
public TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query)
{
if (!int.TryParse(Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))
{
return new TaggedItemCounts();
}
query.Years = [year];
var counts = new TaggedItemCounts();
query.IncludeItemTypes = [BaseItemKind.MusicAlbum];
counts.AlbumCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicArtist];
counts.ArtistCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Episode];
counts.EpisodeCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Movie];
counts.MovieCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.MusicVideo];
counts.MusicVideoCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.LiveTvProgram];
counts.ProgramCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Series];
counts.SeriesCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Audio];
counts.SongCount = LibraryManager.GetCount(query);
query.IncludeItemTypes = [BaseItemKind.Trailer];
counts.TrailerCount = LibraryManager.GetCount(query);
return counts;
}
public int? GetYearValue()
{
if (int.TryParse(Name, NumberStyles.Integer, CultureInfo.InvariantCulture, out var year))

View File

@@ -630,6 +630,8 @@ namespace MediaBrowser.Controller.Library
int GetCount(InternalItemsQuery query);
ItemCounts GetItemCounts(InternalItemsQuery query);
Task RunMetadataSavers(BaseItem item, ItemUpdateType updateReason);
BaseItem GetParentItem(Guid? parentId, Guid? userId);

View File

@@ -84,6 +84,8 @@ public interface IItemRepository
int GetCount(InternalItemsQuery filter);
ItemCounts GetItemCounts(InternalItemsQuery filter);
QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetGenres(InternalItemsQuery filter);
QueryResult<(BaseItem Item, ItemCounts ItemCounts)> GetMusicGenres(InternalItemsQuery filter);