< Summary - Jellyfin

Information
Class: Jellyfin.Server.Implementations.Item.ItemCountBuilder
Assembly: Jellyfin.Server.Implementations
File(s): /srv/git/jellyfin/Jellyfin.Server.Implementations/Item/ItemCountBuilder.cs
Line coverage
85%
Covered lines: 30
Uncovered lines: 5
Coverable lines: 35
Total lines: 100
Line coverage: 85.7%
Branch coverage
80%
Covered branches: 21
Total branches: 26
Branch coverage: 80.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 10/29/2026 - 12:17:11 AM Line coverage: 90.9% (30/33) Branch coverage: 87.5% (21/24) Total lines: 9611/7/2026 - 12:19:31 AM Line coverage: 85.7% (30/35) Branch coverage: 80.7% (21/26) Total lines: 100 10/29/2026 - 12:17:11 AM Line coverage: 90.9% (30/33) Branch coverage: 87.5% (21/24) Total lines: 9611/7/2026 - 12:19:31 AM Line coverage: 85.7% (30/35) Branch coverage: 80.7% (21/26) Total lines: 100

Coverage delta

Coverage delta 7 -7

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Build(...)80.76%292683.87%
SetEpisodeCount(...)100%11100%

File(s)

/srv/git/jellyfin/Jellyfin.Server.Implementations/Item/ItemCountBuilder.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using Jellyfin.Data.Enums;
 4using MediaBrowser.Controller.Persistence;
 5using MediaBrowser.Model.Dto;
 6
 7namespace Jellyfin.Server.Implementations.Item;
 8
 9/// <summary>
 10/// Turns per-type counts into an <see cref="ItemCounts"/>.
 11/// </summary>
 12internal static class ItemCountBuilder
 13{
 14    /// <summary>
 15    /// Builds the counts of one by-name item.
 16    /// </summary>
 17    /// <param name="itemTypeLookup">The item type lookup.</param>
 18    /// <param name="counts">The counted items, by type name. A type may repeat.</param>
 19    /// <returns>The counts.</returns>
 20    public static ItemCounts Build(IItemTypeLookup itemTypeLookup, IEnumerable<(string Type, int Count)> counts)
 21    {
 5722        ArgumentNullException.ThrowIfNull(itemTypeLookup);
 5723        ArgumentNullException.ThrowIfNull(counts);
 24
 5725        var lookup = itemTypeLookup.BaseItemKindNames;
 5726        var result = new ItemCounts();
 27
 24428        foreach (var (type, count) in counts)
 29        {
 30            // Accumulated rather than assigned: a caller may group by something finer than the
 31            // type and hand the same type over more than once.
 6532            if (string.Equals(type, lookup[BaseItemKind.MusicAlbum], StringComparison.Ordinal))
 33            {
 834                result.AlbumCount += count;
 35            }
 5736            else if (string.Equals(type, lookup[BaseItemKind.MusicArtist], StringComparison.Ordinal))
 37            {
 138                result.ArtistCount += count;
 39            }
 5640            else if (string.Equals(type, lookup[BaseItemKind.Episode], StringComparison.Ordinal))
 41            {
 842                result.EpisodeCount += count;
 43            }
 4844            else if (string.Equals(type, lookup[BaseItemKind.Movie], StringComparison.Ordinal))
 45            {
 2946                result.MovieCount += count;
 47            }
 1948            else if (string.Equals(type, lookup[BaseItemKind.MusicVideo], StringComparison.Ordinal))
 49            {
 050                result.MusicVideoCount += count;
 51            }
 1952            else if (string.Equals(type, lookup[BaseItemKind.LiveTvProgram], StringComparison.Ordinal))
 53            {
 054                result.ProgramCount += count;
 55            }
 1956            else if (string.Equals(type, lookup[BaseItemKind.Series], StringComparison.Ordinal))
 57            {
 758                result.SeriesCount += count;
 59            }
 1260            else if (string.Equals(type, lookup[BaseItemKind.Audio], StringComparison.Ordinal))
 61            {
 1062                result.SongCount += count;
 63            }
 264            else if (string.Equals(type, lookup[BaseItemKind.Trailer], StringComparison.Ordinal))
 65            {
 066                result.TrailerCount += count;
 67            }
 268            else if (string.Equals(type, lookup[BaseItemKind.BoxSet], StringComparison.Ordinal))
 69            {
 170                result.BoxSetCount += count;
 71            }
 172            else if (string.Equals(type, lookup[BaseItemKind.Book], StringComparison.Ordinal))
 73            {
 174                result.BookCount += count;
 75            }
 076            else if (string.Equals(type, lookup[BaseItemKind.AudioBook], StringComparison.Ordinal))
 77            {
 078                result.AudioBookCount += count;
 79            }
 80        }
 81
 5782        result.ItemCount = result.TotalItemCount();
 83
 5784        return result;
 85    }
 86
 87    /// <summary>
 88    /// Replaces the episode count, which both by-name paths decide separately from the other
 89    /// types because a genre or studio is usually written on the series rather than its episodes.
 90    /// </summary>
 91    /// <param name="counts">The counts to update.</param>
 92    /// <param name="episodeCount">The episode count.</param>
 93    public static void SetEpisodeCount(ItemCounts counts, int episodeCount)
 94    {
 2895        ArgumentNullException.ThrowIfNull(counts);
 96
 2897        counts.EpisodeCount = episodeCount;
 2898        counts.ItemCount = counts.TotalItemCount();
 2899    }
 100}