From 8166cd3629f2806ab557f8d1a722480ab9c874da Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Sat, 7 Oct 2023 15:53:35 -0400 Subject: [PATCH] ValueTask conversion for controllers --- .../Controllers/AdministrationController.cs | 24 ++++++------- .../Controllers/ApiController.cs | 34 +++++++++--------- .../Controllers/BridgeController.cs | 4 +-- .../Controllers/ByondController.cs | 24 ++++++------- .../Controllers/ChatController.cs | 24 ++++++------- .../ComponentInterfacingController.cs | 8 ++--- .../Controllers/ConfigurationController.cs | 24 ++++++------- .../Controllers/DreamDaemonController.cs | 28 +++++++-------- .../Controllers/DreamMakerController.cs | 22 ++++++------ .../Controllers/HomeController.cs | 8 ++--- .../Controllers/InstanceController.cs | 36 +++++++++---------- .../InstancePermissionSetController.cs | 22 ++++++------ .../Controllers/JobController.cs | 26 +++++++------- .../Controllers/RepositoryController.cs | 20 +++++------ .../Controllers/SwarmController.cs | 18 +++++----- .../Controllers/TransferController.cs | 8 ++--- .../Controllers/UserController.cs | 22 ++++++------ .../Controllers/UserGroupController.cs | 22 ++++++------ .../FileTransferStreamHandlerExtensions.cs | 4 +-- .../Swarm/SwarmRpcMapper.cs | 13 +++++-- .../Swarm/TestableSwarmNode.cs | 6 ++-- 21 files changed, 203 insertions(+), 194 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs index 636aa182a2..b742a2ae18 100644 --- a/src/Tgstation.Server.Host/Controllers/AdministrationController.cs +++ b/src/Tgstation.Server.Host/Controllers/AdministrationController.cs @@ -126,7 +126,7 @@ namespace Tgstation.Server.Host.Controllers /// Get server information. /// /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Retrieved data successfully. /// The GitHub API rate limit was hit. See response header Retry-After. /// A GitHub API error occurred. See error message for details. @@ -135,7 +135,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(AdministrationResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 424)] [ProducesResponseType(typeof(ErrorMessageResponse), 429)] - public async Task Read(CancellationToken cancellationToken) + public async ValueTask Read(CancellationToken cancellationToken) { try { @@ -188,7 +188,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Update has been started successfully. /// The requested release version could not be found in the target GitHub repository. /// Upgrade operations are unavailable due to the launch configuration of TGS. @@ -201,7 +201,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(ErrorMessageResponse), 422)] [ProducesResponseType(typeof(ErrorMessageResponse), 424)] [ProducesResponseType(typeof(ErrorMessageResponse), 429)] - public async Task Update([FromBody] ServerUpdateRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] ServerUpdateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -232,14 +232,14 @@ namespace Tgstation.Server.Host.Controllers /// /// Attempts to restart the server. /// - /// A resulting in the of the request. + /// A resulting in the of the request. /// Restart begun successfully. /// Restart operations are unavailable due to the launch configuration of TGS. [HttpDelete] [TgsAuthorize(AdministrationRights.RestartHost)] [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 422)] - public async Task Delete() + public async ValueTask Delete() { try { @@ -264,14 +264,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Listed logs successfully. /// An IO error occurred while listing. [HttpGet(Routes.Logs)] [TgsAuthorize(AdministrationRights.DownloadLogs)] [ProducesResponseType(typeof(PaginatedResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] - public Task ListLogs([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask ListLogs([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( async () => { @@ -317,14 +317,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The path to download. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Downloaded successfully. /// An IO error occurred while downloading. [HttpGet(Routes.Logs + "/{*path}")] [TgsAuthorize(AdministrationRights.DownloadLogs)] [ProducesResponseType(typeof(LogFileResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] - public async Task GetLog(string path, CancellationToken cancellationToken) + public async ValueTask GetLog(string path, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(path); @@ -369,8 +369,8 @@ namespace Tgstation.Server.Host.Controllers /// The being updated to. /// If an upload is being attempted. /// The for the operation. - /// A resulting in the of the request. - async Task AttemptInitiateUpdate(Version newVersion, bool attemptingUpload, CancellationToken cancellationToken) + /// A resulting in the of the request. + async ValueTask AttemptInitiateUpdate(Version newVersion, bool attemptingUpload, CancellationToken cancellationToken) { IFileUploadTicket uploadTicket = attemptingUpload ? fileTransferService.CreateUpload(FileUploadStreamKind.None) diff --git a/src/Tgstation.Server.Host/Controllers/ApiController.cs b/src/Tgstation.Server.Host/Controllers/ApiController.cs index b3d26b709f..c0f37fbf82 100644 --- a/src/Tgstation.Server.Host/Controllers/ApiController.cs +++ b/src/Tgstation.Server.Host/Controllers/ApiController.cs @@ -257,9 +257,9 @@ namespace Tgstation.Server.Host.Controllers /// Performs validation a request. /// /// The for the operation. - /// A resulting in an appropriate on validation failure, otherwise. - protected virtual Task ValidateRequest(CancellationToken cancellationToken) - => Task.FromResult(null); + /// A resulting in an appropriate on validation failure, otherwise. + protected virtual ValueTask ValidateRequest(CancellationToken cancellationToken) + => ValueTask.FromResult(null); /// /// Response for missing/Invalid headers. @@ -299,10 +299,10 @@ namespace Tgstation.Server.Host.Controllers /// The requested page from the query. /// The requested page size from the query. /// The for the operation. - /// A resulting in the for the operation. - protected Task Paginated( - Func>> queryGenerator, - Func resultTransformer, + /// A resulting in the for the operation. + protected ValueTask Paginated( + Func>> queryGenerator, + Func resultTransformer, int? pageQuery, int? pageSizeQuery, CancellationToken cancellationToken) => PaginatedImpl( @@ -317,15 +317,15 @@ namespace Tgstation.Server.Host.Controllers /// /// The of model being generated. /// The of model being returned. - /// A resulting in a resulting in the generated . + /// A resulting in a resulting in the generated . /// A to transform the s after being queried. /// The requested page from the query. /// The requested page size from the query. /// The for the operation. - /// A resulting in the for the operation. - protected Task Paginated( - Func>> queryGenerator, - Func resultTransformer, + /// A resulting in the for the operation. + protected ValueTask Paginated( + Func>> queryGenerator, + Func resultTransformer, int? pageQuery, int? pageSizeQuery, CancellationToken cancellationToken) @@ -342,15 +342,15 @@ namespace Tgstation.Server.Host.Controllers /// /// The of model being generated. If different from , must implement for . /// The of model being returned. - /// A resulting in a resulting in the generated . + /// A resulting in a resulting in the generated . /// A to transform the s after being queried. /// The requested page from the query. /// The requested page size from the query. /// The for the operation. - /// A resulting in the for the operation. - async Task PaginatedImpl( - Func>> queryGenerator, - Func resultTransformer, + /// A resulting in the for the operation. + async ValueTask PaginatedImpl( + Func>> queryGenerator, + Func resultTransformer, int? pageQuery, int? pageSizeQuery, CancellationToken cancellationToken) diff --git a/src/Tgstation.Server.Host/Controllers/BridgeController.cs b/src/Tgstation.Server.Host/Controllers/BridgeController.cs index 88d445cebc..1f53b43ec2 100644 --- a/src/Tgstation.Server.Host/Controllers/BridgeController.cs +++ b/src/Tgstation.Server.Host/Controllers/BridgeController.cs @@ -74,9 +74,9 @@ namespace Tgstation.Server.Host.Controllers /// /// JSON encoded . /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. [HttpGet] - public async Task Process([FromQuery] string data, CancellationToken cancellationToken) + public async ValueTask Process([FromQuery] string data, CancellationToken cancellationToken) { // Nothing to see here var remoteIP = Request.HttpContext.Connection.RemoteIpAddress; diff --git a/src/Tgstation.Server.Host/Controllers/ByondController.cs b/src/Tgstation.Server.Host/Controllers/ByondController.cs index 92c9878d7b..156ff784e9 100644 --- a/src/Tgstation.Server.Host/Controllers/ByondController.cs +++ b/src/Tgstation.Server.Host/Controllers/ByondController.cs @@ -74,14 +74,14 @@ namespace Tgstation.Server.Host.Controllers /// /// Gets the active . /// - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Retrieved version information successfully. [HttpGet] [TgsAuthorize(ByondRights.ReadActive)] [ProducesResponseType(typeof(ByondResponse), 200)] - public Task Read() + public ValueTask Read() => WithComponentInstance(instance => - Task.FromResult( + ValueTask.FromResult( Json(new ByondResponse { Version = instance.ByondManager.ActiveVersion, @@ -93,15 +93,15 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Retrieved version information successfully. [HttpGet(Routes.List)] [TgsAuthorize(ByondRights.ListInstalled)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => WithComponentInstance( instance => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( instance .ByondManager @@ -122,7 +122,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The containing the to switch to. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Switched active version successfully. /// Created to install and switch active version successfully. [HttpPost] @@ -130,7 +130,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(ByondInstallResponse), 200)] [ProducesResponseType(typeof(ByondInstallResponse), 202)] #pragma warning disable CA1506 // TODO: Decomplexify - public async Task Update([FromBody] ByondVersionRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] ByondVersionRequest model, CancellationToken cancellationToken) #pragma warning restore CA1506 { ArgumentNullException.ThrowIfNull(model); @@ -257,7 +257,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The containing the to delete. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Created to delete target version successfully. /// Attempted to delete the active BYOND . /// The specified was not installed. @@ -266,7 +266,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(JobResponse), 202)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Delete([FromBody] ByondVersionDeleteRequest model, CancellationToken cancellationToken) + public async ValueTask Delete([FromBody] ByondVersionDeleteRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -282,12 +282,12 @@ namespace Tgstation.Server.Host.Controllers var byondManager = instance.ByondManager; if (version == byondManager.ActiveVersion) - return Task.FromResult( + return ValueTask.FromResult( Conflict(new ErrorMessageResponse(ErrorCode.ByondCannotDeleteActiveVersion))); var versionNotInstalled = !byondManager.InstalledVersions.Any(x => x == version); - return Task.FromResult( + return ValueTask.FromResult( versionNotInstalled ? this.Gone() : null); diff --git a/src/Tgstation.Server.Host/Controllers/ChatController.cs b/src/Tgstation.Server.Host/Controllers/ChatController.cs index 8b8004cb69..c1365b1f84 100644 --- a/src/Tgstation.Server.Host/Controllers/ChatController.cs +++ b/src/Tgstation.Server.Host/Controllers/ChatController.cs @@ -99,12 +99,12 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Created successfully. [HttpPut] [TgsAuthorize(ChatBotRights.Create)] [ProducesResponseType(typeof(ChatBotResponse), 201)] - public async Task Create([FromBody] ChatBotCreateRequest model, CancellationToken cancellationToken) + public async ValueTask Create([FromBody] ChatBotCreateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -173,12 +173,12 @@ namespace Tgstation.Server.Host.Controllers /// /// The to delete. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Chat bot deleted or does not exist. [HttpDelete("{id}")] [TgsAuthorize(ChatBotRights.Delete)] [ProducesResponseType(204)] - public async Task Delete(long id, CancellationToken cancellationToken) + public async ValueTask Delete(long id, CancellationToken cancellationToken) => await WithComponentInstance( async instance => { @@ -200,16 +200,16 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Listed chat bots successfully. [HttpGet(Routes.List)] [TgsAuthorize(ChatBotRights.Read)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) { var connectionStrings = (AuthenticationContext.GetRight(RightsType.ChatBots) & (ulong)ChatBotRights.ReadConnectionString) != 0; return Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( DatabaseContext .ChatBots @@ -222,7 +222,7 @@ namespace Tgstation.Server.Host.Controllers if (!connectionStrings) chatBot.ConnectionString = null; - return Task.CompletedTask; + return ValueTask.CompletedTask; }, page, pageSize, @@ -234,14 +234,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The to retrieve. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Retrieved successfully. /// The with the given ID does not exist in this instance. [HttpGet("{id}")] [TgsAuthorize(ChatBotRights.Read)] [ProducesResponseType(typeof(ChatBotResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { var query = DatabaseContext.ChatBots .AsQueryable() @@ -265,7 +265,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Update applied successfully. /// Update applied successfully. not returned based on user permissions. /// The with the given ID does not exist in this instance. @@ -275,7 +275,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1502, CA1506 // TODO: Decomplexify - public async Task Update([FromBody] ChatBotUpdateRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] ChatBotUpdateRequest model, CancellationToken cancellationToken) #pragma warning restore CA1502, CA1506 { ArgumentNullException.ThrowIfNull(model); diff --git a/src/Tgstation.Server.Host/Controllers/ComponentInterfacingController.cs b/src/Tgstation.Server.Host/Controllers/ComponentInterfacingController.cs index bab9ae1e62..45e3829bbb 100644 --- a/src/Tgstation.Server.Host/Controllers/ComponentInterfacingController.cs +++ b/src/Tgstation.Server.Host/Controllers/ComponentInterfacingController.cs @@ -60,7 +60,7 @@ namespace Tgstation.Server.Host.Controllers } /// - protected override async Task ValidateRequest(CancellationToken cancellationToken) + protected override async ValueTask ValidateRequest(CancellationToken cancellationToken) { if (!useInstanceRequestHeader) return null; @@ -113,11 +113,11 @@ namespace Tgstation.Server.Host.Controllers /// /// Run a given with the relevant . /// - /// A accepting the and returning a with the . + /// A accepting the and returning a with the . /// The to grab. If , will be used. - /// A resulting in the that should be returned. + /// A resulting in the that should be returned. /// The context of should be as small as possible so as to avoid race conditions. This function can return a if the requested instance was offline. - protected async Task WithComponentInstance(Func> action, Models.Instance instance = null) + protected async ValueTask WithComponentInstance(Func> action, Models.Instance instance = null) { ArgumentNullException.ThrowIfNull(action); diff --git a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs index 6be4c6df5f..b71703af41 100644 --- a/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs +++ b/src/Tgstation.Server.Host/Controllers/ConfigurationController.cs @@ -58,14 +58,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The representing the file. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// File updated successfully. /// File upload ticket created successfully. [HttpPost] [TgsAuthorize(ConfigurationRights.Write)] [ProducesResponseType(typeof(ConfigurationFileResponse), 200)] [ProducesResponseType(typeof(ConfigurationFileResponse), 202)] - public async Task Update([FromBody] ConfigurationFileRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] ConfigurationFileRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); if (ForbidDueToModeConflicts(model.Path, out var systemIdentity)) @@ -109,7 +109,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The path of the file to get. /// The for the operation. - /// A resulting in the for the operation.> + /// A resulting in the for the operation.> /// File read successfully.> /// File does not currently exist. [HttpGet(Routes.File + "/{*filePath}")] @@ -117,7 +117,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(ConfigurationFileResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task File(string filePath, CancellationToken cancellationToken) + public async ValueTask File(string filePath, CancellationToken cancellationToken) { if (ForbidDueToModeConflicts(filePath, out var systemIdentity)) return Forbid(); @@ -158,7 +158,7 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Directory listed successfully.> /// Directory does not currently exist. [HttpGet(Routes.List + "/{*directoryPath}")] @@ -166,7 +166,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(PaginatedResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public Task Directory( + public ValueTask Directory( string directoryPath, [FromQuery] int? page, [FromQuery] int? pageSize, @@ -222,11 +222,11 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. [HttpGet(Routes.List)] [TgsAuthorize(ConfigurationRights.List)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List( + public ValueTask List( [FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Directory(null, page, pageSize, cancellationToken); @@ -236,7 +236,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The representing the directory. /// The for the operation. - /// A resulting in the for the operation. + /// A resulting in the for the operation. /// Directory already exists. /// Directory created successfully. [HttpPut] @@ -244,7 +244,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(ConfigurationFileResponse), 200)] [ProducesResponseType(typeof(ConfigurationFileResponse), 201)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] - public async Task CreateDirectory([FromBody] ConfigurationFileRequest model, CancellationToken cancellationToken) + public async ValueTask CreateDirectory([FromBody] ConfigurationFileRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -297,13 +297,13 @@ namespace Tgstation.Server.Host.Controllers /// /// A representing the path to the directory to delete. /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Empty directory deleted successfully. [HttpDelete] [TgsAuthorize(ConfigurationRights.Delete)] [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] - public async Task DeleteDirectory([FromBody] ConfigurationFileRequest directory, CancellationToken cancellationToken) + public async ValueTask DeleteDirectory([FromBody] ConfigurationFileRequest directory, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(directory); diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 10d179792c..f4613f81d0 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -73,12 +73,12 @@ namespace Tgstation.Server.Host.Controllers /// Launches the watchdog. /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Watchdog launch started successfully. [HttpPut] [TgsAuthorize(DreamDaemonRights.Start)] [ProducesResponseType(typeof(JobResponse), 202)] - public Task Create(CancellationToken cancellationToken) + public ValueTask Create(CancellationToken cancellationToken) => WithComponentInstance(async instance => { if (instance.Watchdog.Status != WatchdogStatus.Offline) @@ -103,25 +103,25 @@ namespace Tgstation.Server.Host.Controllers /// Get the watchdog status. /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Read information successfully. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpGet] [TgsAuthorize(DreamDaemonRights.ReadMetadata | DreamDaemonRights.ReadRevision)] [ProducesResponseType(typeof(DreamDaemonResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public Task Read(CancellationToken cancellationToken) => ReadImpl(null, cancellationToken); + public ValueTask Read(CancellationToken cancellationToken) => ReadImpl(null, cancellationToken); /// /// Stops the Watchdog if it's running. /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Watchdog terminated. [HttpDelete] [TgsAuthorize(DreamDaemonRights.Shutdown)] [ProducesResponseType(204)] - public Task Delete(CancellationToken cancellationToken) + public ValueTask Delete(CancellationToken cancellationToken) => WithComponentInstance(async instance => { await instance.Watchdog.Terminate(false, cancellationToken); @@ -133,7 +133,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The with updated settings. /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Settings applied successfully. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPost] @@ -157,7 +157,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1502 // TODO: Decomplexify #pragma warning disable CA1506 - public async Task Update([FromBody] DreamDaemonRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] DreamDaemonRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -259,12 +259,12 @@ namespace Tgstation.Server.Host.Controllers /// Creates a to restart the Watchdog. It will not start if it wasn't already running. /// /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Restart started successfully. [HttpPatch] [TgsAuthorize(DreamDaemonRights.Restart)] [ProducesResponseType(typeof(JobResponse), 202)] - public Task Restart(CancellationToken cancellationToken) + public ValueTask Restart(CancellationToken cancellationToken) => WithComponentInstance(async instance => { var job = new Job @@ -292,12 +292,12 @@ namespace Tgstation.Server.Host.Controllers /// Creates a to generate a DreamDaemon process dump. /// /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Dump started successfully. [HttpPatch(Routes.Diagnostics)] [TgsAuthorize(DreamDaemonRights.CreateDump)] [ProducesResponseType(typeof(JobResponse), 202)] - public Task CreateDump(CancellationToken cancellationToken) + public ValueTask CreateDump(CancellationToken cancellationToken) => WithComponentInstance(async instance => { var job = new Job @@ -326,8 +326,8 @@ namespace Tgstation.Server.Host.Controllers /// /// The to operate on if any. /// The for the operation. - /// A resulting in the of the operation. - Task ReadImpl(DreamDaemonSettings settings, CancellationToken cancellationToken) + /// A resulting in the of the operation. + ValueTask ReadImpl(DreamDaemonSettings settings, CancellationToken cancellationToken) => WithComponentInstance(async instance => { var dd = instance.Watchdog; diff --git a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs index d26c23aba2..3c4431a3e1 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamMakerController.cs @@ -69,12 +69,12 @@ namespace Tgstation.Server.Host.Controllers /// Read current deployment settings. /// /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Read deployment settings successfully. [HttpGet] [TgsAuthorize(DreamMakerRights.Read)] [ProducesResponseType(typeof(DreamMakerResponse), 200)] - public async Task Read(CancellationToken cancellationToken) + public async ValueTask Read(CancellationToken cancellationToken) { var dreamMakerSettings = await DatabaseContext .DreamMakerSettings @@ -89,14 +89,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// retrieved successfully. /// Specified ID does not exist in this instance. [HttpGet("{id}")] [TgsAuthorize(DreamMakerRights.CompileJobs)] [ProducesResponseType(typeof(CompileJobResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 404)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { var compileJob = await BaseCompileJobsQuery() .Where(x => x.Id == id) @@ -112,14 +112,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved s successfully. [HttpGet(Routes.List)] [TgsAuthorize(DreamMakerRights.CompileJobs)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( BaseCompileJobsQuery() .OrderByDescending(x => x.Job.StoppedAt))), @@ -132,12 +132,12 @@ namespace Tgstation.Server.Host.Controllers /// Begin deploying repository code. /// /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Created deployment successfully. [HttpPut] [TgsAuthorize(DreamMakerRights.Compile)] [ProducesResponseType(typeof(JobResponse), 202)] - public async Task Create(CancellationToken cancellationToken) + public async ValueTask Create(CancellationToken cancellationToken) { var job = new Job { @@ -161,7 +161,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Changes applied successfully. The updated will be returned. /// Changes applied successfully. The updated will be not be returned due to permissions. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. @@ -175,7 +175,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(DreamMakerResponse), 200)] [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Update([FromBody] DreamMakerRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] DreamMakerRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); diff --git a/src/Tgstation.Server.Host/Controllers/HomeController.cs b/src/Tgstation.Server.Host/Controllers/HomeController.cs index a7286839a2..a0be005e9e 100644 --- a/src/Tgstation.Server.Host/Controllers/HomeController.cs +++ b/src/Tgstation.Server.Host/Controllers/HomeController.cs @@ -147,14 +147,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The for the operation. /// - /// A resuting in the containing of the if a properly authenticated API request, the web control panel if on a browser and enabled, otherwise. + /// A resuting in the containing of the if a properly authenticated API request, the web control panel if on a browser and enabled, otherwise. /// /// retrieved successfully. [HttpGet] [AllowAnonymous] [ProducesResponseType(typeof(ServerInformationResponse), 200)] #pragma warning disable CA1506 - public async Task Home(CancellationToken cancellationToken) + public async ValueTask Home(CancellationToken cancellationToken) { if (controlPanelConfiguration.Enable) Response.Headers.Add( @@ -211,7 +211,7 @@ namespace Tgstation.Server.Host.Controllers /// Attempt to authenticate a using . /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// User logged in and generated successfully. /// User authentication failed. /// User authenticated but is disabled by an administrator. @@ -220,7 +220,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(TokenResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 429)] #pragma warning disable CA1506 // TODO: Decomplexify - public async Task CreateToken(CancellationToken cancellationToken) + public async ValueTask CreateToken(CancellationToken cancellationToken) { if (ApiHeaders == null) { diff --git a/src/Tgstation.Server.Host/Controllers/InstanceController.cs b/src/Tgstation.Server.Host/Controllers/InstanceController.cs index 0b29b869a6..0e2ebf234e 100644 --- a/src/Tgstation.Server.Host/Controllers/InstanceController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstanceController.cs @@ -120,14 +120,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Instance attached successfully. /// Instance created successfully. [HttpPut] [TgsAuthorize(InstanceManagerRights.Create)] [ProducesResponseType(typeof(InstanceResponse), 200)] [ProducesResponseType(typeof(InstanceResponse), 201)] - public async Task Create([FromBody] InstanceCreateRequest model, CancellationToken cancellationToken) + public async ValueTask Create([FromBody] InstanceCreateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -199,7 +199,7 @@ namespace Tgstation.Server.Host.Controllers .Any(path => InstanceIsChildOf(path)) ?? true)) return BadRequest(new ErrorMessageResponse(ErrorCode.InstanceNotAtWhitelistedPath)); - async Task DirExistsAndIsNotEmpty() + async ValueTask DirExistsAndIsNotEmpty() { if (!await ioManager.DirectoryExists(model.Path, cancellationToken)) return false; @@ -272,14 +272,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The of the instance to detach. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Instance detatched successfully. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpDelete("{id}")] [TgsAuthorize(InstanceManagerRights.Delete)] [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Delete(long id, CancellationToken cancellationToken) + public async ValueTask Delete(long id, CancellationToken cancellationToken) { var originalModel = await DatabaseContext .Instances @@ -315,7 +315,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The updated settings. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Instance updated successfully. /// Instance updated successfully and relocation job created. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. @@ -325,7 +325,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(InstanceResponse), 202)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1502 // TODO: Decomplexify - public async Task Update([FromBody] InstanceUpdateRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] InstanceUpdateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -512,12 +512,12 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved s successfully. [HttpGet(Routes.List)] [TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public async Task List( + public async ValueTask List( [FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) @@ -552,7 +552,7 @@ namespace Tgstation.Server.Host.Controllers var needsUpdate = false; var result = await Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( GetBaseQuery() .OrderBy(x => x.Id))), @@ -577,14 +577,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The instance to retrieve. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved successfully. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpGet("{id}")] [TgsAuthorize(InstanceManagerRights.List | InstanceManagerRights.Read)] [ProducesResponseType(typeof(InstanceResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { var cantList = !AuthenticationContext.PermissionSet.InstanceManagerRights.Value.HasFlag(InstanceManagerRights.List); IQueryable QueryForUser() @@ -634,13 +634,13 @@ namespace Tgstation.Server.Host.Controllers /// /// The instance to give permissions on. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Granted permissions successfully. [HttpPatch("{id}")] [TgsAuthorize(InstanceManagerRights.GrantPermissions)] [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task GrantPermissions(long id, CancellationToken cancellationToken) + public async ValueTask GrantPermissions(long id, CancellationToken cancellationToken) { IQueryable BaseQuery() => DatabaseContext .Instances @@ -678,8 +678,8 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the new or if ports could not be allocated. - async Task CreateDefaultInstance(InstanceCreateRequest initialSettings, CancellationToken cancellationToken) + /// A resulting in the new or if ports could not be allocated. + async ValueTask CreateDefaultInstance(InstanceCreateRequest initialSettings, CancellationToken cancellationToken) { var ddPort = await portAllocator.GetAvailablePort(1024, false, cancellationToken); if (!ddPort.HasValue) @@ -797,8 +797,8 @@ namespace Tgstation.Server.Host.Controllers /// /// The to populate. /// The for the operation. - /// A representing the running operation. - async Task CheckAccessible(InstanceResponse instanceResponse, CancellationToken cancellationToken) + /// A representing the running operation. + async ValueTask CheckAccessible(InstanceResponse instanceResponse, CancellationToken cancellationToken) { instanceResponse.Accessible = await DatabaseContext .InstancePermissionSets diff --git a/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs b/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs index e0be1eb3b1..ca8fdae67b 100644 --- a/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs +++ b/src/Tgstation.Server.Host/Controllers/InstancePermissionSetController.cs @@ -53,7 +53,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// created successfully. /// The does not exist. [HttpPut] @@ -61,7 +61,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(InstancePermissionSetResponse), 201)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1506 - public async Task Create([FromBody] InstancePermissionSetRequest model, CancellationToken cancellationToken) + public async ValueTask Create([FromBody] InstancePermissionSetRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -116,7 +116,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// updated successfully. /// The requested does not currently exist. [HttpPost] @@ -124,7 +124,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(InstancePermissionSetResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1506 // TODO: Decomplexify - public async Task Update([FromBody] InstancePermissionSetRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] InstancePermissionSetRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -174,14 +174,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved s successfully. [HttpGet(Routes.List)] [TgsAuthorize(InstancePermissionSetRights.Read)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( DatabaseContext .Instances @@ -199,14 +199,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieve successfully. /// The requested does not currently exist. [HttpGet("{id}")] [TgsAuthorize(InstancePermissionSetRights.Read)] [ProducesResponseType(typeof(InstancePermissionSetResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { // this functions as userId var permissionSet = await DatabaseContext @@ -226,14 +226,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The to delete. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Target deleted. /// Target or no longer exists. [HttpDelete("{id}")] [TgsAuthorize(InstancePermissionSetRights.Write)] [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Delete(long id, CancellationToken cancellationToken) + public async ValueTask Delete(long id, CancellationToken cancellationToken) { var numDeleted = await DatabaseContext .Instances diff --git a/src/Tgstation.Server.Host/Controllers/JobController.cs b/src/Tgstation.Server.Host/Controllers/JobController.cs index 77f1221b51..84f4cc5084 100644 --- a/src/Tgstation.Server.Host/Controllers/JobController.cs +++ b/src/Tgstation.Server.Host/Controllers/JobController.cs @@ -59,14 +59,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved active s successfully. [HttpGet] [TgsAuthorize] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task Read([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask Read([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( DatabaseContext .Jobs @@ -86,14 +86,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved s successfully. [HttpGet(Routes.List)] [TgsAuthorize] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( DatabaseContext .Jobs @@ -112,7 +112,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The of the to cancel. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// cancellation requested successfully. /// does not exist in this instance. /// could not be found in the job manager. Has it already completed?. @@ -120,7 +120,7 @@ namespace Tgstation.Server.Host.Controllers [TgsAuthorize] [ProducesResponseType(typeof(JobResponse), 202)] [ProducesResponseType(typeof(ErrorMessageResponse), 404)] - public async Task Delete(long id, CancellationToken cancellationToken) + public async ValueTask Delete(long id, CancellationToken cancellationToken) { // don't care if an instance post or not at this point var job = await DatabaseContext @@ -147,14 +147,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The of the to retrieve. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved successfully. /// does not exist in this instance. [HttpGet("{id}")] [TgsAuthorize] [ProducesResponseType(typeof(JobResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 404)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { var job = await DatabaseContext .Jobs @@ -174,11 +174,11 @@ namespace Tgstation.Server.Host.Controllers /// Supplements s with their . /// /// The to augment. - /// A representing the running operation. - Task AddJobProgressResponseTransformer(JobResponse jobResponse) + /// A representing the running operation. + ValueTask AddJobProgressResponseTransformer(JobResponse jobResponse) { jobManager.SetJobProgress(jobResponse); - return Task.CompletedTask; + return ValueTask.CompletedTask; } } } diff --git a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs index 6b877c054b..0b02d7d0c1 100644 --- a/src/Tgstation.Server.Host/Controllers/RepositoryController.cs +++ b/src/Tgstation.Server.Host/Controllers/RepositoryController.cs @@ -73,14 +73,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// The repository was created successfully and the to clone it has begun. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpPut] [TgsAuthorize(RepositoryRights.SetOrigin)] [ProducesResponseType(typeof(RepositoryResponse), 201)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Create([FromBody] RepositoryCreateRequest model, CancellationToken cancellationToken) + public async ValueTask Create([FromBody] RepositoryCreateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -193,14 +193,14 @@ namespace Tgstation.Server.Host.Controllers /// Delete the repository. /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Job to delete the repository created successfully. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. [HttpDelete] [TgsAuthorize(RepositoryRights.Delete)] [ProducesResponseType(typeof(RepositoryResponse), 202)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Delete(CancellationToken cancellationToken) + public async ValueTask Delete(CancellationToken cancellationToken) { var currentModel = await DatabaseContext .RepositorySettings @@ -237,7 +237,7 @@ namespace Tgstation.Server.Host.Controllers /// Get the repository's status. /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Retrieved the repository settings successfully. /// Retrieved the repository settings successfully, though they did not previously exist. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. @@ -246,7 +246,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(RepositoryResponse), 200)] [ProducesResponseType(typeof(RepositoryResponse), 201)] [ProducesResponseType(typeof(RepositoryResponse), 410)] - public async Task Read(CancellationToken cancellationToken) + public async ValueTask Read(CancellationToken cancellationToken) { var currentModel = await DatabaseContext .RepositorySettings @@ -287,7 +287,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Updated the repository settings successfully. /// Updated the repository settings successfully and a was created to make the requested git changes. /// The database entity for the requested instance could not be retrieved. The instance was likely detached. @@ -306,7 +306,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(RepositoryResponse), 202)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1502 // TODO: Decomplexify - public async Task Update([FromBody] RepositoryUpdateRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] RepositoryUpdateRequest model, CancellationToken cancellationToken) #pragma warning restore CA1502 { ArgumentNullException.ThrowIfNull(model); @@ -484,8 +484,8 @@ namespace Tgstation.Server.Host.Controllers /// The active . /// The active . /// The for the operation. - /// A resulting in if the was modified in a way that requires saving, otherwise. - async Task PopulateApi( + /// A resulting in if the was modified in a way that requires saving, otherwise. + async ValueTask PopulateApi( RepositoryResponse apiResponse, IRepository repository, IDatabaseContext databaseContext, diff --git a/src/Tgstation.Server.Host/Controllers/SwarmController.cs b/src/Tgstation.Server.Host/Controllers/SwarmController.cs index a94599c920..8b941d425c 100644 --- a/src/Tgstation.Server.Host/Controllers/SwarmController.cs +++ b/src/Tgstation.Server.Host/Controllers/SwarmController.cs @@ -89,7 +89,7 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// The of the operation. [HttpPost(SwarmConstants.RegisterRoute)] - public async Task Register([FromBody] SwarmRegistrationRequest registrationRequest, CancellationToken cancellationToken) + public async ValueTask Register([FromBody] SwarmRegistrationRequest registrationRequest, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(registrationRequest); @@ -108,7 +108,7 @@ namespace Tgstation.Server.Host.Controllers /// The for the operation. /// A resulting in the of the operation. [HttpDelete(SwarmConstants.RegisterRoute)] - public async Task UnregisterNode(CancellationToken cancellationToken) + public async ValueTask UnregisterNode(CancellationToken cancellationToken) { if (!ValidateRegistration()) return Forbid(); @@ -138,7 +138,7 @@ namespace Tgstation.Server.Host.Controllers /// A resulting in the of the operation. [HttpGet(SwarmConstants.UpdateRoute)] [Produces(MediaTypeNames.Application.Octet)] - public Task GetUpdatePackage([FromQuery] string ticket, CancellationToken cancellationToken) + public ValueTask GetUpdatePackage([FromQuery] string ticket, CancellationToken cancellationToken) => transferService.GenerateDownloadResponse(this, ticket, cancellationToken); /// @@ -163,9 +163,9 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. [HttpPut(SwarmConstants.UpdateRoute)] - public async Task PrepareUpdate([FromBody] SwarmUpdateRequest updateRequest, CancellationToken cancellationToken) + public async ValueTask PrepareUpdate([FromBody] SwarmUpdateRequest updateRequest, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(updateRequest); @@ -183,9 +183,9 @@ namespace Tgstation.Server.Host.Controllers /// Update commit endpoint. /// /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. [HttpPost(SwarmConstants.UpdateRoute)] - public async Task CommitUpdate(CancellationToken cancellationToken) + public async ValueTask CommitUpdate(CancellationToken cancellationToken) { if (!ValidateRegistration()) return Forbid(); @@ -199,9 +199,9 @@ namespace Tgstation.Server.Host.Controllers /// /// Update abort endpoint. /// - /// A resulting in the of the operation. + /// A resulting in the of the operation. [HttpDelete(SwarmConstants.UpdateRoute)] - public async Task AbortUpdate() + public async ValueTask AbortUpdate() { if (!ValidateRegistration()) return Forbid(); diff --git a/src/Tgstation.Server.Host/Controllers/TransferController.cs b/src/Tgstation.Server.Host/Controllers/TransferController.cs index 6374b65557..be12cfda91 100644 --- a/src/Tgstation.Server.Host/Controllers/TransferController.cs +++ b/src/Tgstation.Server.Host/Controllers/TransferController.cs @@ -54,14 +54,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The for the download. /// The for the operation. - /// A resulting in the of the method. + /// A resulting in the of the method. /// Started streaming download successfully. /// The was no longer or was never valid. [TgsAuthorize] [HttpGet] [ProducesResponseType(200, Type = typeof(LimitedStreamResult))] [ProducesResponseType(410, Type = typeof(ErrorMessageResponse))] - public Task Download([Required, FromQuery] string ticket, CancellationToken cancellationToken) + public ValueTask Download([Required, FromQuery] string ticket, CancellationToken cancellationToken) => fileTransferService.GenerateDownloadResponse(this, ticket, cancellationToken); /// @@ -69,7 +69,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The for the upload. /// The for the operation. - /// A resulting in the of the method. + /// A resulting in the of the method. /// Uploaded file successfully. /// An error occurred during the upload. /// The was no longer or was never valid. @@ -77,7 +77,7 @@ namespace Tgstation.Server.Host.Controllers [HttpPut] [ProducesResponseType(204)] [ProducesResponseType(410, Type = typeof(ErrorMessageResponse))] - public async Task Upload([Required, FromQuery] string ticket, CancellationToken cancellationToken) + public async ValueTask Upload([Required, FromQuery] string ticket, CancellationToken cancellationToken) { if (ticket == null) return BadRequest(new ErrorMessageResponse(ErrorCode.ModelValidationFailure)); diff --git a/src/Tgstation.Server.Host/Controllers/UserController.cs b/src/Tgstation.Server.Host/Controllers/UserController.cs index b50e424c93..04559bde3c 100644 --- a/src/Tgstation.Server.Host/Controllers/UserController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserController.cs @@ -75,14 +75,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// created successfully. /// The requested system identifier could not be found. [HttpPut] [TgsAuthorize(AdministrationRights.WriteUsers)] [ProducesResponseType(typeof(UserResponse), 201)] #pragma warning disable CA1502, CA1506 - public async Task Create([FromBody] UserCreateRequest model, CancellationToken cancellationToken) + public async ValueTask Create([FromBody] UserCreateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -155,7 +155,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The to update. /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// updated successfully. /// updated successfully. Not returned due to lack of permissions. /// Requested does not exist. @@ -168,7 +168,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(typeof(ErrorMessageResponse), 410)] #pragma warning disable CA1502 // TODO: Decomplexify #pragma warning disable CA1506 - public async Task Update([FromBody] UserUpdateRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] UserUpdateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -336,14 +336,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// Retrieved s successfully. [HttpGet(Routes.List)] [TgsAuthorize(AdministrationRights.ReadUsers)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( DatabaseContext .Users @@ -365,14 +365,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The to retrieve. /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// The was retrieved successfully. /// The does not exist. [HttpGet("{id}")] [TgsAuthorize] [ProducesResponseType(typeof(UserResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 404)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { if (id == AuthenticationContext.User.Id) return Read(); @@ -403,8 +403,8 @@ namespace Tgstation.Server.Host.Controllers /// /// The to use as a template. /// The for the operation. - /// A resulting in a new on success, if the requested did not exist. - async Task CreateNewUserFromModel(Api.Models.Internal.UserApiBase model, CancellationToken cancellationToken) + /// A resulting in a new on success, if the requested did not exist. + async ValueTask CreateNewUserFromModel(Api.Models.Internal.UserApiBase model, CancellationToken cancellationToken) { Models.PermissionSet permissionSet = null; UserGroup group = null; diff --git a/src/Tgstation.Server.Host/Controllers/UserGroupController.cs b/src/Tgstation.Server.Host/Controllers/UserGroupController.cs index 7b794d86e5..14269e3254 100644 --- a/src/Tgstation.Server.Host/Controllers/UserGroupController.cs +++ b/src/Tgstation.Server.Host/Controllers/UserGroupController.cs @@ -60,12 +60,12 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// created successfully. [HttpPut] [TgsAuthorize(AdministrationRights.WriteUsers)] [ProducesResponseType(typeof(UserGroupResponse), 201)] - public async Task Create([FromBody] UserGroupCreateRequest model, CancellationToken cancellationToken) + public async ValueTask Create([FromBody] UserGroupCreateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -103,13 +103,13 @@ namespace Tgstation.Server.Host.Controllers /// /// The . /// The for the operation. - /// A resulting in the of the operation. + /// A resulting in the of the operation. /// updated successfully. /// The requested does not currently exist. [HttpPost] [TgsAuthorize(AdministrationRights.WriteUsers)] [ProducesResponseType(typeof(UserGroupResponse), 200)] - public async Task Update([FromBody] UserGroupUpdateRequest model, CancellationToken cancellationToken) + public async ValueTask Update([FromBody] UserGroupUpdateRequest model, CancellationToken cancellationToken) { ArgumentNullException.ThrowIfNull(model); @@ -148,14 +148,14 @@ namespace Tgstation.Server.Host.Controllers /// /// The of the . /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieve successfully. /// The requested does not currently exist. [HttpGet("{id}")] [TgsAuthorize(AdministrationRights.ReadUsers)] [ProducesResponseType(typeof(UserGroupResponse), 200)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task GetId(long id, CancellationToken cancellationToken) + public async ValueTask GetId(long id, CancellationToken cancellationToken) { // this functions as userId var group = await DatabaseContext @@ -176,14 +176,14 @@ namespace Tgstation.Server.Host.Controllers /// The current page. /// The page size. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// Retrieved s successfully. [HttpGet(Routes.List)] [TgsAuthorize(AdministrationRights.ReadUsers)] [ProducesResponseType(typeof(PaginatedResponse), 200)] - public Task List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) + public ValueTask List([FromQuery] int? page, [FromQuery] int? pageSize, CancellationToken cancellationToken) => Paginated( - () => Task.FromResult( + () => ValueTask.FromResult( new PaginatableResult( DatabaseContext .Groups @@ -201,7 +201,7 @@ namespace Tgstation.Server.Host.Controllers /// /// The of the to delete. /// The for the operation. - /// A resulting in the of the request. + /// A resulting in the of the request. /// was deleted. /// The is not empty. /// The didn't exist. @@ -210,7 +210,7 @@ namespace Tgstation.Server.Host.Controllers [ProducesResponseType(204)] [ProducesResponseType(typeof(ErrorMessageResponse), 409)] [ProducesResponseType(typeof(ErrorMessageResponse), 410)] - public async Task Delete(long id, CancellationToken cancellationToken) + public async ValueTask Delete(long id, CancellationToken cancellationToken) { var numDeleted = await DatabaseContext .Groups diff --git a/src/Tgstation.Server.Host/Extensions/FileTransferStreamHandlerExtensions.cs b/src/Tgstation.Server.Host/Extensions/FileTransferStreamHandlerExtensions.cs index 83cd739213..8028f8ab8d 100644 --- a/src/Tgstation.Server.Host/Extensions/FileTransferStreamHandlerExtensions.cs +++ b/src/Tgstation.Server.Host/Extensions/FileTransferStreamHandlerExtensions.cs @@ -28,8 +28,8 @@ namespace Tgstation.Server.Host.Extensions /// The the request is coming from. /// The for the download. /// The for the operation. - /// A resulting in the of the method. - public static async Task GenerateDownloadResponse( + /// A resulting in the of the method. + public static async ValueTask GenerateDownloadResponse( this IFileTransferStreamHandler fileTransferService, ControllerBase controller, string ticket, diff --git a/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs b/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs index d019ce54f5..167c058c19 100644 --- a/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs +++ b/tests/Tgstation.Server.Host.Tests/Swarm/SwarmRpcMapper.cs @@ -184,12 +184,21 @@ namespace Tgstation.Server.Host.Swarm.Tests if (controllerMethod.ReturnType != typeof(IActionResult)) { - Assert.AreEqual(typeof(Task), controllerMethod.ReturnType); + var isValueTask = controllerMethod.ReturnType == typeof(ValueTask); + if (!isValueTask) + Assert.AreEqual(typeof(Task), controllerMethod.ReturnType); + var lastParam = controllerMethod.GetParameters().LastOrDefault(); if (lastParam?.ParameterType == typeof(CancellationToken)) args.Add(cancellationToken); - var invocationTask = (Task)controllerMethod.Invoke(controller, args.ToArray()); + var rawTask = controllerMethod.Invoke(controller, args.ToArray()); + Task invocationTask; + if (isValueTask) + invocationTask = ((ValueTask)rawTask).AsTask(); + else + invocationTask = (Task)rawTask; + result = await invocationTask; } else diff --git a/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs b/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs index 0c780e04f4..0021948045 100644 --- a/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs +++ b/tests/Tgstation.Server.Host.Tests/Swarm/TestableSwarmNode.cs @@ -270,18 +270,18 @@ namespace Tgstation.Server.Host.Swarm.Tests return result; } - Task BeginUpdate(ISwarmService swarmService, IFileStreamProvider fileStreamProvider, Version version, CancellationToken cancellationToken) + ValueTask BeginUpdate(ISwarmService swarmService, IFileStreamProvider fileStreamProvider, Version version, CancellationToken cancellationToken) { logger.LogTrace("BeginUpdate..."); if (UpdateTask?.IsCompleted == false) - return Task.FromResult(ServerUpdateResult.UpdateInProgress); + return ValueTask.FromResult(ServerUpdateResult.UpdateInProgress); if (UpdateResult == ServerUpdateResult.Started) { UpdateTask = ExecuteUpdate(fileStreamProvider, version, cancellationToken, CriticalCancellationTokenSource.Token); } - return Task.FromResult(UpdateResult); + return ValueTask.FromResult(UpdateResult); } async Task ExecuteUpdate(IFileStreamProvider fileStreamProvider, Version version, CancellationToken cancellationToken, CancellationToken criticalCancellationToken)