mirror of
https://github.com/lidarr/Lidarr
synced 2024-12-22 07:42:28 +00:00
Cache root folders for artist paths
(cherry picked from commit 63fdf8ca8ff9b22ce4cf8764cc05aad5d1d0ae62)
This commit is contained in:
parent
07b3ebb1aa
commit
54607eb2e0
1 changed files with 25 additions and 11 deletions
|
@ -5,6 +5,7 @@
|
|||
using System.Threading.Tasks;
|
||||
using NLog;
|
||||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Disk;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.MediaFiles;
|
||||
|
@ -33,15 +34,20 @@ public class RootFolderService : IRootFolderService
|
|||
private readonly IManageCommandQueue _commandQueueManager;
|
||||
private readonly Logger _logger;
|
||||
|
||||
private readonly ICached<string> _cache;
|
||||
|
||||
public RootFolderService(IRootFolderRepository rootFolderRepository,
|
||||
IDiskProvider diskProvider,
|
||||
IManageCommandQueue commandQueueManager,
|
||||
ICacheManager cacheManager,
|
||||
Logger logger)
|
||||
{
|
||||
_rootFolderRepository = rootFolderRepository;
|
||||
_diskProvider = diskProvider;
|
||||
_commandQueueManager = commandQueueManager;
|
||||
_logger = logger;
|
||||
|
||||
_cache = cacheManager.GetCache<string>(GetType());
|
||||
}
|
||||
|
||||
public List<RootFolder> All()
|
||||
|
@ -89,7 +95,7 @@ private void VerifyRootFolder(RootFolder rootFolder)
|
|||
|
||||
if (!_diskProvider.FolderWritable(rootFolder.Path))
|
||||
{
|
||||
throw new UnauthorizedAccessException(string.Format("Root folder path '{0}' is not writable by user '{1}'", rootFolder.Path, Environment.UserName));
|
||||
throw new UnauthorizedAccessException($"Root folder path '{rootFolder.Path}' is not writable by user '{Environment.UserName}'");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -107,6 +113,7 @@ public RootFolder Add(RootFolder rootFolder)
|
|||
_commandQueueManager.Push(new RescanFoldersCommand(new List<string> { rootFolder.Path }, FilterFilesType.None, true, null));
|
||||
|
||||
GetDetails(rootFolder, true);
|
||||
_cache.Clear();
|
||||
|
||||
return rootFolder;
|
||||
}
|
||||
|
@ -118,6 +125,7 @@ public RootFolder Update(RootFolder rootFolder)
|
|||
_rootFolderRepository.Update(rootFolder);
|
||||
|
||||
GetDetails(rootFolder, true);
|
||||
_cache.Clear();
|
||||
|
||||
return rootFolder;
|
||||
}
|
||||
|
@ -125,6 +133,7 @@ public RootFolder Update(RootFolder rootFolder)
|
|||
public void Remove(int id)
|
||||
{
|
||||
_rootFolderRepository.Delete(id);
|
||||
_cache.Clear();
|
||||
}
|
||||
|
||||
public RootFolder Get(int id, bool timeout)
|
||||
|
@ -148,16 +157,7 @@ public RootFolder GetBestRootFolder(string path)
|
|||
|
||||
public string GetBestRootFolderPath(string path)
|
||||
{
|
||||
var possibleRootFolder = GetBestRootFolder(path);
|
||||
|
||||
if (possibleRootFolder == null)
|
||||
{
|
||||
var osPath = new OsPath(path);
|
||||
|
||||
return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\');
|
||||
}
|
||||
|
||||
return possibleRootFolder?.Path;
|
||||
return _cache.Get(path, () => GetBestRootFolderPathInternal(path), TimeSpan.FromDays(1));
|
||||
}
|
||||
|
||||
private void GetDetails(RootFolder rootFolder, bool timeout)
|
||||
|
@ -172,5 +172,19 @@ private void GetDetails(RootFolder rootFolder, bool timeout)
|
|||
}
|
||||
}).Wait(timeout ? 5000 : -1);
|
||||
}
|
||||
|
||||
private string GetBestRootFolderPathInternal(string path)
|
||||
{
|
||||
var possibleRootFolder = GetBestRootFolder(path);
|
||||
|
||||
if (possibleRootFolder == null)
|
||||
{
|
||||
var osPath = new OsPath(path);
|
||||
|
||||
return osPath.Directory.ToString().TrimEnd(osPath.IsUnixPath ? '/' : '\\');
|
||||
}
|
||||
|
||||
return possibleRootFolder?.Path;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue