mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 09:34:44 +01:00
Merge pull request #6096 from cvium/saving_private_ram
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Channels;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
@@ -52,7 +53,7 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||
var typeOptions = libraryOptions.GetTypeOptions(baseItem.GetType().Name);
|
||||
if (typeOptions != null)
|
||||
{
|
||||
return typeOptions.MetadataFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
||||
return typeOptions.MetadataFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
if (!libraryOptions.EnableInternetProviders)
|
||||
@@ -62,7 +63,7 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||
|
||||
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, GetType().Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
return itemConfig == null || !itemConfig.DisabledMetadataFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
||||
return itemConfig == null || !itemConfig.DisabledMetadataFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -83,7 +84,7 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||
var typeOptions = libraryOptions.GetTypeOptions(baseItem.GetType().Name);
|
||||
if (typeOptions != null)
|
||||
{
|
||||
return typeOptions.ImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
||||
return typeOptions.ImageFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
if (!libraryOptions.EnableInternetProviders)
|
||||
@@ -93,7 +94,7 @@ namespace MediaBrowser.Controller.BaseItemManager
|
||||
|
||||
var itemConfig = _serverConfigurationManager.Configuration.MetadataOptions.FirstOrDefault(i => string.Equals(i.ItemType, GetType().Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name, StringComparer.OrdinalIgnoreCase);
|
||||
return itemConfig == null || !itemConfig.DisabledImageFetchers.Contains(name.AsSpan(), StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -670,14 +670,12 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
if (SourceType == SourceType.Channel)
|
||||
{
|
||||
return System.IO.Path.Combine(basePath, "channels", ChannelId.ToString("N", CultureInfo.InvariantCulture), Id.ToString("N", CultureInfo.InvariantCulture));
|
||||
return System.IO.Path.Join(basePath, "channels", ChannelId.ToString("N", CultureInfo.InvariantCulture), Id.ToString("N", CultureInfo.InvariantCulture));
|
||||
}
|
||||
|
||||
ReadOnlySpan<char> idString = Id.ToString("N", CultureInfo.InvariantCulture);
|
||||
|
||||
basePath = System.IO.Path.Combine(basePath, "library");
|
||||
|
||||
return System.IO.Path.Join(basePath, idString.Slice(0, 2), idString);
|
||||
return System.IO.Path.Join(basePath, "library", idString.Slice(0, 2), idString);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1262,7 +1260,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
|
||||
// Support plex/xbmc convention
|
||||
files.AddRange(fileSystemChildren
|
||||
.Where(i => !i.IsDirectory && string.Equals(FileSystem.GetFileNameWithoutExtension(i), ThemeSongFilename, StringComparison.OrdinalIgnoreCase)));
|
||||
.Where(i => !i.IsDirectory && System.IO.Path.GetFileNameWithoutExtension(i.FullName.AsSpan()).Equals(ThemeSongFilename, StringComparison.OrdinalIgnoreCase)));
|
||||
|
||||
return LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions())
|
||||
.OfType<Audio.Audio>()
|
||||
@@ -1323,14 +1321,16 @@ namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
var extras = new List<Video>();
|
||||
|
||||
var folders = fileSystemChildren.Where(i => i.IsDirectory).ToArray();
|
||||
var libraryOptions = new LibraryOptions();
|
||||
var folders = fileSystemChildren.Where(i => i.IsDirectory).ToList();
|
||||
foreach (var extraFolderName in AllExtrasTypesFolderNames)
|
||||
{
|
||||
var files = folders
|
||||
.Where(i => string.Equals(i.Name, extraFolderName, StringComparison.OrdinalIgnoreCase))
|
||||
.SelectMany(i => FileSystem.GetFiles(i.FullName));
|
||||
|
||||
extras.AddRange(LibraryManager.ResolvePaths(files, directoryService, null, new LibraryOptions())
|
||||
// Re-using the same instance of LibraryOptions since it looks like it's never being altered.
|
||||
extras.AddRange(LibraryManager.ResolvePaths(files, directoryService, null, libraryOptions)
|
||||
.OfType<Video>()
|
||||
.Select(item =>
|
||||
{
|
||||
@@ -2327,7 +2327,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
.Where(i => i.IsLocalFile)
|
||||
.Select(i => System.IO.Path.GetDirectoryName(i.Path))
|
||||
.Distinct(StringComparer.OrdinalIgnoreCase)
|
||||
.SelectMany(directoryService.GetFilePaths)
|
||||
.SelectMany(path => directoryService.GetFilePaths(path))
|
||||
.ToList();
|
||||
|
||||
var deletedImages = ImageInfos
|
||||
@@ -2436,7 +2436,15 @@ namespace MediaBrowser.Controller.Entities
|
||||
throw new ArgumentException("No image info for chapter images");
|
||||
}
|
||||
|
||||
return ImageInfos.Where(i => i.Type == imageType);
|
||||
// Yield return is more performant than LINQ Where on an Array
|
||||
for (var i = 0; i < ImageInfos.Length; i++)
|
||||
{
|
||||
var imageInfo = ImageInfos[i];
|
||||
if (imageInfo.Type == imageType)
|
||||
{
|
||||
yield return imageInfo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -2468,7 +2476,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
|
||||
var existing = existingImages
|
||||
.FirstOrDefault(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase));
|
||||
.Find(i => string.Equals(i.Path, newImage.FullName, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (existing == null)
|
||||
{
|
||||
@@ -2499,8 +2507,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
var newImagePaths = images.Select(i => i.FullName).ToList();
|
||||
|
||||
var deleted = existingImages
|
||||
.Where(i => i.IsLocalFile && !newImagePaths.Contains(i.Path, StringComparer.OrdinalIgnoreCase) && !File.Exists(i.Path))
|
||||
.ToList();
|
||||
.FindAll(i => i.IsLocalFile && !newImagePaths.Contains(i.Path.AsSpan(), StringComparison.OrdinalIgnoreCase) && !File.Exists(i.Path));
|
||||
|
||||
if (deleted.Count > 0)
|
||||
{
|
||||
|
||||
@@ -22,6 +22,27 @@ namespace MediaBrowser.Controller.Extensions
|
||||
return Normalize(string.Concat(chars), NormalizationForm.FormC);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Counts the number of occurrences of [needle] in the string.
|
||||
/// </summary>
|
||||
/// <param name="value">The haystack to search in.</param>
|
||||
/// <param name="needle">The character to search for.</param>
|
||||
/// <returns>The number of occurrences of the [needle] character.</returns>
|
||||
public static int CountOccurrences(this ReadOnlySpan<char> value, char needle)
|
||||
{
|
||||
var count = 0;
|
||||
var length = value.Length;
|
||||
for (var i = 0; i < length; i++)
|
||||
{
|
||||
if (value[i] == needle)
|
||||
{
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
private static string Normalize(string text, NormalizationForm form, bool stripStringOnFailure = true)
|
||||
{
|
||||
if (stripStringOnFailure)
|
||||
|
||||
@@ -6,6 +6,7 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Emby.Naming.Common;
|
||||
using Jellyfin.Data.Entities;
|
||||
using Jellyfin.Data.Enums;
|
||||
using MediaBrowser.Controller.Dto;
|
||||
@@ -595,5 +596,11 @@ namespace MediaBrowser.Controller.Library
|
||||
BaseItem GetParentItem(string parentId, Guid? userId);
|
||||
|
||||
BaseItem GetParentItem(Guid? parentId, Guid? userId);
|
||||
|
||||
/// <summary>
|
||||
/// Gets or creates a static instance of <see cref="NamingOptions"/>.
|
||||
/// </summary>
|
||||
/// <returns>An instance of the <see cref="NamingOptions"/> class.</returns>
|
||||
NamingOptions GetNamingOptions();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,9 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\MediaBrowser.Model\MediaBrowser.Model.csproj" />
|
||||
<ProjectReference Include="..\MediaBrowser.Common\MediaBrowser.Common.csproj" />
|
||||
<ProjectReference Include="../Emby.Naming/Emby.Naming.csproj" />
|
||||
<ProjectReference Include="../MediaBrowser.Model/MediaBrowser.Model.csproj" />
|
||||
<ProjectReference Include="../MediaBrowser.Common/MediaBrowser.Common.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@@ -25,15 +25,16 @@ namespace MediaBrowser.Controller.Providers
|
||||
|
||||
public FileSystemMetadata[] GetFileSystemEntries(string path)
|
||||
{
|
||||
return _cache.GetOrAdd(path, p => _fileSystem.GetFileSystemEntries(p).ToArray());
|
||||
return _cache.GetOrAdd(path, (p, fileSystem) => fileSystem.GetFileSystemEntries(p).ToArray(), _fileSystem);
|
||||
}
|
||||
|
||||
public List<FileSystemMetadata> GetFiles(string path)
|
||||
{
|
||||
var list = new List<FileSystemMetadata>();
|
||||
var items = GetFileSystemEntries(path);
|
||||
foreach (var item in items)
|
||||
for (var i = 0; i < items.Length; i++)
|
||||
{
|
||||
var item = items[i];
|
||||
if (!item.IsDirectory)
|
||||
{
|
||||
list.Add(item);
|
||||
@@ -48,10 +49,9 @@ namespace MediaBrowser.Controller.Providers
|
||||
if (!_fileCache.TryGetValue(path, out var result))
|
||||
{
|
||||
var file = _fileSystem.GetFileInfo(path);
|
||||
var res = file != null && file.Exists ? file : null;
|
||||
if (res != null)
|
||||
if (file.Exists)
|
||||
{
|
||||
result = res;
|
||||
result = file;
|
||||
_fileCache.TryAdd(path, result);
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,21 @@ namespace MediaBrowser.Controller.Providers
|
||||
public IReadOnlyList<string> GetFilePaths(string path)
|
||||
=> GetFilePaths(path, false);
|
||||
|
||||
public IReadOnlyList<string> GetFilePaths(string path, bool clearCache)
|
||||
public IReadOnlyList<string> GetFilePaths(string path, bool clearCache, bool sort = false)
|
||||
{
|
||||
if (clearCache)
|
||||
{
|
||||
_filePathCache.TryRemove(path, out _);
|
||||
}
|
||||
|
||||
return _filePathCache.GetOrAdd(path, p => _fileSystem.GetFilePaths(p).ToList());
|
||||
var filePaths = _filePathCache.GetOrAdd(path, (p, fileSystem) => fileSystem.GetFilePaths(p).ToList(), _fileSystem);
|
||||
|
||||
if (sort)
|
||||
{
|
||||
filePaths.Sort();
|
||||
}
|
||||
|
||||
return filePaths;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,6 @@ namespace MediaBrowser.Controller.Providers
|
||||
|
||||
IReadOnlyList<string> GetFilePaths(string path);
|
||||
|
||||
IReadOnlyList<string> GetFilePaths(string path, bool clearCache);
|
||||
IReadOnlyList<string> GetFilePaths(string path, bool clearCache, bool sort = false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,16 +12,26 @@ namespace MediaBrowser.Controller.Providers
|
||||
{
|
||||
public class MetadataResult<T>
|
||||
{
|
||||
// Images aren't always used so the allocation is a waste a lot of the time
|
||||
private List<LocalImageInfo> _images;
|
||||
private List<(string url, ImageType type)> _remoteImages;
|
||||
|
||||
public MetadataResult()
|
||||
{
|
||||
Images = new List<LocalImageInfo>();
|
||||
RemoteImages = new List<(string url, ImageType type)>();
|
||||
ResultLanguage = "en";
|
||||
}
|
||||
|
||||
public List<LocalImageInfo> Images { get; set; }
|
||||
public List<LocalImageInfo> Images
|
||||
{
|
||||
get => _images ??= new List<LocalImageInfo>();
|
||||
set => _images = value;
|
||||
}
|
||||
|
||||
public List<(string url, ImageType type)> RemoteImages { get; set; }
|
||||
public List<(string url, ImageType type)> RemoteImages
|
||||
{
|
||||
get => _remoteImages ??= new List<(string url, ImageType type)>();
|
||||
set => _remoteImages = value;
|
||||
}
|
||||
|
||||
public List<UserItemData> UserDataList { get; set; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user