mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-01-15 08:23:28 -03:00
Refactor to pull item counts in a single query
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -10,8 +10,6 @@ namespace MediaBrowser.Controller.Entities
|
||||
public interface IItemByName
|
||||
{
|
||||
IReadOnlyList<BaseItem> GetTaggedItems(InternalItemsQuery query);
|
||||
|
||||
TaggedItemCounts GetTaggedItemCounts(InternalItemsQuery query);
|
||||
}
|
||||
|
||||
public interface IHasDualAccess : IItemByName
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user