< Summary - Jellyfin

Information
Class: Jellyfin.Server.Migrations.Routines.RemoveDuplicatePlaylistChildren
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/RemoveDuplicatePlaylistChildren.cs
Line coverage
0%
Covered lines: 0
Uncovered lines: 24
Coverable lines: 24
Total lines: 64
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 6
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%210%
get_Id()100%210%
get_Name()100%210%
get_PerformOnNewInstall()100%210%
Perform()0%4260%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Migrations/Routines/RemoveDuplicatePlaylistChildren.cs

#LineLine coverage
 1using System;
 2using System.Linq;
 3using System.Threading;
 4using Jellyfin.Data.Enums;
 5using MediaBrowser.Controller.Entities;
 6using MediaBrowser.Controller.Library;
 7using MediaBrowser.Controller.Playlists;
 8
 9namespace Jellyfin.Server.Migrations.Routines;
 10
 11/// <summary>
 12/// Remove duplicate playlist entries.
 13/// </summary>
 14internal class RemoveDuplicatePlaylistChildren : IMigrationRoutine
 15{
 16    private readonly ILibraryManager _libraryManager;
 17    private readonly IPlaylistManager _playlistManager;
 18
 19    public RemoveDuplicatePlaylistChildren(
 20        ILibraryManager libraryManager,
 21        IPlaylistManager playlistManager)
 22    {
 023        _libraryManager = libraryManager;
 024        _playlistManager = playlistManager;
 025    }
 26
 27    /// <inheritdoc/>
 028    public Guid Id => Guid.Parse("{96C156A2-7A13-4B3B-A8B8-FB80C94D20C0}");
 29
 30    /// <inheritdoc/>
 031    public string Name => "RemoveDuplicatePlaylistChildren";
 32
 33    /// <inheritdoc/>
 034    public bool PerformOnNewInstall => false;
 35
 36    /// <inheritdoc/>
 37    public void Perform()
 38    {
 039        var playlists = _libraryManager.GetItemList(new InternalItemsQuery
 040        {
 041            IncludeItemTypes = [BaseItemKind.Playlist]
 042        })
 043        .Cast<Playlist>()
 044        .Where(p => !p.OpenAccess || !p.OwnerUserId.Equals(Guid.Empty))
 045        .ToArray();
 46
 047        if (playlists.Length > 0)
 48        {
 049            foreach (var playlist in playlists)
 50            {
 051                var linkedChildren = playlist.LinkedChildren;
 052                if (linkedChildren.Length > 0)
 53                {
 054                    var nullItemChildren = linkedChildren.Where(c => c.ItemId is null);
 055                    var deduplicatedChildren = linkedChildren.DistinctBy(c => c.ItemId);
 056                    var newLinkedChildren = nullItemChildren.Concat(deduplicatedChildren);
 057                    playlist.LinkedChildren = linkedChildren;
 058                    playlist.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).GetAwaiter().G
 059                    _playlistManager.SavePlaylistFile(playlist);
 60                }
 61            }
 62        }
 063    }
 64}