Merge pull request #6096 from cvium/saving_private_ram

This commit is contained in:
Bond-009
2021-06-12 00:20:54 +02:00
committed by GitHub
44 changed files with 1146 additions and 910 deletions

View File

@@ -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;
}
}
}

View File

@@ -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);
}
}

View File

@@ -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; }