mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-12-24 01:34:45 +03:00
Merge pull request #6096 from cvium/saving_private_ram
This commit is contained in:
@@ -696,25 +696,32 @@ namespace Emby.Server.Implementations.Library
|
||||
}
|
||||
|
||||
private IEnumerable<BaseItem> ResolveFileList(
|
||||
IEnumerable<FileSystemMetadata> fileList,
|
||||
IReadOnlyList<FileSystemMetadata> fileList,
|
||||
IDirectoryService directoryService,
|
||||
Folder parent,
|
||||
string collectionType,
|
||||
IItemResolver[] resolvers,
|
||||
LibraryOptions libraryOptions)
|
||||
{
|
||||
return fileList.Select(f =>
|
||||
// Given that fileList is a list we can save enumerator allocations by indexing
|
||||
for (var i = 0; i < fileList.Count; i++)
|
||||
{
|
||||
var file = fileList[i];
|
||||
BaseItem result = null;
|
||||
try
|
||||
{
|
||||
return ResolvePath(f, directoryService, resolvers, parent, collectionType, libraryOptions);
|
||||
result = ResolvePath(file, directoryService, resolvers, parent, collectionType, libraryOptions);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Error resolving path {path}", f.FullName);
|
||||
return null;
|
||||
_logger.LogError(ex, "Error resolving path {Path}", file.FullName);
|
||||
}
|
||||
}).Where(i => i != null);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
yield return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2076,7 +2083,7 @@ namespace Emby.Server.Implementations.Library
|
||||
return new List<Folder>();
|
||||
}
|
||||
|
||||
return GetCollectionFoldersInternal(item, GetUserRootFolder().Children.OfType<Folder>().ToList());
|
||||
return GetCollectionFoldersInternal(item, GetUserRootFolder().Children.OfType<Folder>());
|
||||
}
|
||||
|
||||
public List<Folder> GetCollectionFolders(BaseItem item, List<Folder> allUserRootChildren)
|
||||
@@ -2101,10 +2108,10 @@ namespace Emby.Server.Implementations.Library
|
||||
return GetCollectionFoldersInternal(item, allUserRootChildren);
|
||||
}
|
||||
|
||||
private static List<Folder> GetCollectionFoldersInternal(BaseItem item, List<Folder> allUserRootChildren)
|
||||
private static List<Folder> GetCollectionFoldersInternal(BaseItem item, IEnumerable<Folder> allUserRootChildren)
|
||||
{
|
||||
return allUserRootChildren
|
||||
.Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path, StringComparer.OrdinalIgnoreCase))
|
||||
.Where(i => string.Equals(i.Path, item.Path, StringComparison.OrdinalIgnoreCase) || i.PhysicalLocations.Contains(item.Path.AsSpan(), StringComparison.OrdinalIgnoreCase))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -2112,9 +2119,9 @@ namespace Emby.Server.Implementations.Library
|
||||
{
|
||||
if (!(item is CollectionFolder collectionFolder))
|
||||
{
|
||||
// List.Find is more performant than FirstOrDefault due to enumerator allocation
|
||||
collectionFolder = GetCollectionFolders(item)
|
||||
.OfType<CollectionFolder>()
|
||||
.FirstOrDefault();
|
||||
.Find(folder => folder is CollectionFolder) as CollectionFolder;
|
||||
}
|
||||
|
||||
return collectionFolder == null ? new LibraryOptions() : collectionFolder.GetLibraryOptions();
|
||||
@@ -2500,8 +2507,7 @@ namespace Emby.Server.Implementations.Library
|
||||
/// <inheritdoc />
|
||||
public bool IsVideoFile(string path)
|
||||
{
|
||||
var resolver = new VideoResolver(GetNamingOptions());
|
||||
return resolver.IsVideoFile(path);
|
||||
return VideoResolver.IsVideoFile(path, GetNamingOptions());
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -2679,6 +2685,7 @@ namespace Emby.Server.Implementations.Library
|
||||
return changed;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public NamingOptions GetNamingOptions()
|
||||
{
|
||||
if (_namingOptions == null)
|
||||
@@ -2692,13 +2699,12 @@ namespace Emby.Server.Implementations.Library
|
||||
|
||||
public ItemLookupInfo ParseName(string name)
|
||||
{
|
||||
var resolver = new VideoResolver(GetNamingOptions());
|
||||
|
||||
var result = resolver.CleanDateTime(name);
|
||||
var namingOptions = GetNamingOptions();
|
||||
var result = VideoResolver.CleanDateTime(name, namingOptions);
|
||||
|
||||
return new ItemLookupInfo
|
||||
{
|
||||
Name = resolver.TryCleanString(result.Name, out var newName) ? newName.ToString() : result.Name,
|
||||
Name = VideoResolver.TryCleanString(result.Name, namingOptions, out var newName) ? newName.ToString() : result.Name,
|
||||
Year = result.Year
|
||||
};
|
||||
}
|
||||
@@ -2712,9 +2718,7 @@ namespace Emby.Server.Implementations.Library
|
||||
.SelectMany(i => _fileSystem.GetFiles(i.FullName, _videoFileExtensions, false, false))
|
||||
.ToList();
|
||||
|
||||
var videoListResolver = new VideoListResolver(namingOptions);
|
||||
|
||||
var videos = videoListResolver.Resolve(fileSystemChildren);
|
||||
var videos = VideoListResolver.Resolve(fileSystemChildren, namingOptions);
|
||||
|
||||
var currentVideo = videos.FirstOrDefault(i => string.Equals(owner.Path, i.Files[0].Path, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
@@ -2758,9 +2762,7 @@ namespace Emby.Server.Implementations.Library
|
||||
.SelectMany(i => _fileSystem.GetFiles(i.FullName, _videoFileExtensions, false, false))
|
||||
.ToList();
|
||||
|
||||
var videoListResolver = new VideoListResolver(namingOptions);
|
||||
|
||||
var videos = videoListResolver.Resolve(fileSystemChildren);
|
||||
var videos = VideoListResolver.Resolve(fileSystemChildren, namingOptions);
|
||||
|
||||
var currentVideo = videos.FirstOrDefault(i => string.Equals(owner.Path, i.Files[0].Path, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user