From af1e2fe2ebc9b17dc280fb48f2e081ecf5842caa Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 13 Jun 2020 12:15:58 -0700 Subject: [PATCH] Add timeout parameter to root folder endpoint Closes #1468 Closes #1556 --- .../RootFolders/RootFolderController.cs | 5 ++++- .../RootFolders/RootFolderService.cs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Lidarr.Api.V1/RootFolders/RootFolderController.cs b/src/Lidarr.Api.V1/RootFolders/RootFolderController.cs index f1f06ccdc..bce093c6f 100644 --- a/src/Lidarr.Api.V1/RootFolders/RootFolderController.cs +++ b/src/Lidarr.Api.V1/RootFolders/RootFolderController.cs @@ -1,6 +1,7 @@ using System.Collections.Generic; using FluentValidation; using Lidarr.Http; +using Lidarr.Http.Extensions; using Lidarr.Http.REST; using Lidarr.Http.REST.Attributes; using Microsoft.AspNetCore.Mvc; @@ -56,7 +57,9 @@ namespace Lidarr.Api.V1.RootFolders public override RootFolderResource GetResourceById(int id) { - return _rootFolderService.Get(id).ToResource(); + var timeout = Request?.GetBooleanQueryParameter("timeout", true) ?? true; + + return _rootFolderService.Get(id, timeout).ToResource(); } [RestPostById] diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index 709b75750..1b5c57f31 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -20,7 +20,7 @@ namespace NzbDrone.Core.RootFolders RootFolder Add(RootFolder rootFolder); RootFolder Update(RootFolder rootFolder); void Remove(int id); - RootFolder Get(int id); + RootFolder Get(int id, bool timeout); List AllForTag(int tagId); RootFolder GetBestRootFolder(string path); string GetBestRootFolderPath(string path); @@ -61,7 +61,7 @@ namespace NzbDrone.Core.RootFolders { if (folder.Path.IsPathValid(PathValidationType.CurrentOs)) { - GetDetails(folder); + GetDetails(folder, true); } } @@ -106,7 +106,7 @@ namespace NzbDrone.Core.RootFolders _commandQueueManager.Push(new RescanFoldersCommand(new List { rootFolder.Path }, FilterFilesType.None, true, null)); - GetDetails(rootFolder); + GetDetails(rootFolder, true); return rootFolder; } @@ -117,7 +117,7 @@ namespace NzbDrone.Core.RootFolders _rootFolderRepository.Update(rootFolder); - GetDetails(rootFolder); + GetDetails(rootFolder, true); return rootFolder; } @@ -127,10 +127,10 @@ namespace NzbDrone.Core.RootFolders _rootFolderRepository.Delete(id); } - public RootFolder Get(int id) + public RootFolder Get(int id, bool timeout) { var rootFolder = _rootFolderRepository.Get(id); - GetDetails(rootFolder); + GetDetails(rootFolder, timeout); return rootFolder; } @@ -160,7 +160,7 @@ namespace NzbDrone.Core.RootFolders return possibleRootFolder?.Path; } - private void GetDetails(RootFolder rootFolder) + private void GetDetails(RootFolder rootFolder, bool timeout) { Task.Run(() => { @@ -170,7 +170,7 @@ namespace NzbDrone.Core.RootFolders rootFolder.FreeSpace = _diskProvider.GetAvailableSpace(rootFolder.Path); rootFolder.TotalSpace = _diskProvider.GetTotalSize(rootFolder.Path); } - }).Wait(5000); + }).Wait(timeout ? 5000 : -1); } } }