Merge pull request #13790 from crobibero/fix-build

Fix build and tests
This commit is contained in:
Niels van Velzen 2025-03-28 07:21:59 +01:00 committed by GitHub
commit 7f5cc544df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 13 additions and 11 deletions

View File

@ -1,8 +1,8 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Jellyfin.Database.Implementations.Entities;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;

View File

@ -1,19 +1,21 @@
#pragma warning disable CS1591 #pragma warning disable CS1591
using System; using System;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using BitFaster.Caching.Lru;
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
namespace MediaBrowser.Controller.Providers namespace MediaBrowser.Controller.Providers
{ {
public class DirectoryService : IDirectoryService public class DirectoryService : IDirectoryService
{ {
// These caches are primarily used for scanning so no reason to have them be large. // TODO make static and switch to FastConcurrentLru.
private static readonly FastConcurrentLru<string, FileSystemMetadata[]> _cache = new(Environment.ProcessorCount, Math.Max(128, Environment.ProcessorCount * 10), StringComparer.Ordinal); private readonly ConcurrentDictionary<string, FileSystemMetadata[]> _cache = new(StringComparer.Ordinal);
private static readonly FastConcurrentLru<string, FileSystemMetadata> _fileCache = new(Environment.ProcessorCount, Math.Max(128, Environment.ProcessorCount * 10), StringComparer.Ordinal);
private static readonly FastConcurrentLru<string, List<string>> _filePathCache = new(Environment.ProcessorCount, Math.Max(128, Environment.ProcessorCount * 10), StringComparer.Ordinal); private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache = new(StringComparer.Ordinal);
private readonly ConcurrentDictionary<string, List<string>> _filePathCache = new(StringComparer.Ordinal);
private readonly IFileSystem _fileSystem; private readonly IFileSystem _fileSystem;
@ -73,13 +75,13 @@ namespace MediaBrowser.Controller.Providers
public FileSystemMetadata? GetFileSystemEntry(string path) public FileSystemMetadata? GetFileSystemEntry(string path)
{ {
if (!_fileCache.TryGet(path, out var result)) if (!_fileCache.TryGetValue(path, out var result))
{ {
var file = _fileSystem.GetFileSystemInfo(path); var file = _fileSystem.GetFileSystemInfo(path);
if (file?.Exists ?? false) if (file?.Exists ?? false)
{ {
result = file; result = file;
_fileCache.AddOrUpdate(path, result); _fileCache.TryAdd(path, result);
} }
} }

View File

@ -209,7 +209,7 @@ namespace Jellyfin.Controller.Tests
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths); fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths);
var directoryService = new DirectoryService(fileSystemMock.Object); var directoryService = new DirectoryService(fileSystemMock.Object);
var result = directoryService.GetFilePaths(path, true); var result = directoryService.GetFilePaths(path);
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths); fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths);
var secondResult = directoryService.GetFilePaths(path); var secondResult = directoryService.GetFilePaths(path);
@ -241,7 +241,7 @@ namespace Jellyfin.Controller.Tests
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths); fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(cachedPaths);
var directoryService = new DirectoryService(fileSystemMock.Object); var directoryService = new DirectoryService(fileSystemMock.Object);
var result = directoryService.GetFilePaths(path, true); var result = directoryService.GetFilePaths(path);
fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths); fileSystemMock.Setup(f => f.GetFilePaths(It.Is<string>(x => x == path), false)).Returns(newPaths);
var secondResult = directoryService.GetFilePaths(path, true); var secondResult = directoryService.GetFilePaths(path, true);

View File

@ -1,6 +1,6 @@
using System; using System;
using Jellyfin.Data.Entities;
using Jellyfin.Data.Enums; using Jellyfin.Data.Enums;
using Jellyfin.Database.Implementations.Entities;
using Jellyfin.Server.Implementations.Item; using Jellyfin.Server.Implementations.Item;
using MediaBrowser.Controller.Entities; using MediaBrowser.Controller.Entities;
using Xunit; using Xunit;