< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Entities.UserRootFolder
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Entities/UserRootFolder.cs
Line coverage
74%
Covered lines: 29
Uncovered lines: 10
Coverable lines: 39
Total lines: 141
Line coverage: 74.3%
Branch coverage
66%
Covered branches: 4
Total branches: 6
Branch coverage: 66.6%
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%11100%
get_SupportsInheritedParentImages()100%11100%
get_SupportsPlayedStatus()100%210%
get_SupportsShortcutChildren()100%11100%
get_IsPreSorted()100%210%
ClearCache()100%11100%
LoadChildren()100%22100%
GetItemsInternal(...)0%620%
GetChildCount(...)100%11100%
GetEligibleChildrenForRecursiveChildren(...)100%11100%
BeforeMetadataRefresh(...)100%22100%
GetNonCachedChildren(...)100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Entities/UserRootFolder.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Linq;
 8using System.Text.Json.Serialization;
 9using System.Threading;
 10using System.Threading.Tasks;
 11using Jellyfin.Data.Entities;
 12using MediaBrowser.Controller.Providers;
 13using MediaBrowser.Model.Library;
 14using MediaBrowser.Model.Querying;
 15
 16namespace MediaBrowser.Controller.Entities
 17{
 18    /// <summary>
 19    /// Special class used for User Roots.  Children contain actual ones defined for this user
 20    /// PLUS the virtual folders from the physical root (added by plug-ins).
 21    /// </summary>
 22    public class UserRootFolder : Folder
 23    {
 4524        private readonly object _childIdsLock = new object();
 25        private List<Guid> _childrenIds = null;
 26
 27        /// <summary>
 28        /// Initializes a new instance of the <see cref="UserRootFolder"/> class.
 29        /// </summary>
 4530        public UserRootFolder()
 31        {
 4532            IsRoot = true;
 4533        }
 34
 35        [JsonIgnore]
 1136        public override bool SupportsInheritedParentImages => false;
 37
 38        [JsonIgnore]
 039        public override bool SupportsPlayedStatus => false;
 40
 41        [JsonIgnore]
 6342        protected override bool SupportsShortcutChildren => true;
 43
 44        [JsonIgnore]
 045        public override bool IsPreSorted => true;
 46
 47        private void ClearCache()
 48        {
 8449            lock (_childIdsLock)
 50            {
 8451                _childrenIds = null;
 8452            }
 8453        }
 54
 55        protected override List<BaseItem> LoadChildren()
 56        {
 79157            lock (_childIdsLock)
 58            {
 79159                if (_childrenIds is null)
 60                {
 8561                    var list = base.LoadChildren();
 8562                    _childrenIds = list.Select(i => i.Id).ToList();
 8563                    return list;
 64                }
 65
 70666                return _childrenIds.Select(LibraryManager.GetItemById).Where(i => i is not null).ToList();
 67            }
 79168        }
 69
 70        protected override QueryResult<BaseItem> GetItemsInternal(InternalItemsQuery query)
 71        {
 072            if (query.Recursive)
 73            {
 074                return QueryRecursive(query);
 75            }
 76
 077            var result = UserViewManager.GetUserViews(new UserViewQuery
 078            {
 079                User = query.User,
 080                PresetViews = query.PresetViews
 081            });
 82
 083            return UserViewBuilder.SortAndPage(result, null, query, LibraryManager, true);
 84        }
 85
 86        public override int GetChildCount(User user)
 87        {
 1188            return GetChildren(user, true).Count;
 89        }
 90
 91        protected override IEnumerable<BaseItem> GetEligibleChildrenForRecursiveChildren(User user)
 92        {
 1593            var list = base.GetEligibleChildrenForRecursiveChildren(user).ToList();
 1594            list.AddRange(LibraryManager.RootFolder.VirtualChildren);
 95
 1596            return list;
 97        }
 98
 99        public override bool BeforeMetadataRefresh(bool replaceAllMetadata)
 100        {
 21101            ClearCache();
 21102            var hasChanges = base.BeforeMetadataRefresh(replaceAllMetadata);
 103
 21104            if (string.Equals("default", Name, StringComparison.OrdinalIgnoreCase))
 105            {
 17106                Name = "Media Folders";
 17107                hasChanges = true;
 108            }
 109
 21110            return hasChanges;
 111        }
 112
 113        protected override IEnumerable<BaseItem> GetNonCachedChildren(IDirectoryService directoryService)
 114        {
 21115            ClearCache();
 116
 21117            return base.GetNonCachedChildren(directoryService);
 118        }
 119
 120        protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshC
 121        {
 122            ClearCache();
 123
 124            await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, allowRemoveRoot, refreshOptio
 125                .ConfigureAwait(false);
 126
 127            ClearCache();
 128
 129            // Not the best way to handle this, but it solves an issue
 130            // CollectionFolders aren't always getting saved after changes
 131            // This means that grabbing the item by Id may end up returning the old one
 132            // Fix is in two places - make sure the folder gets saved
 133            // And here to remedy it for affected users.
 134            // In theory this can be removed eventually.
 135            foreach (var item in Children)
 136            {
 137                LibraryManager.RegisterItem(item);
 138            }
 139        }
 140    }
 141}