New Backoffice: Published cache controller (#13034)

* Add published cache controller (endpoints for the Published Status dashboard)

* Update OpenAPI contract for published cache endpoints

* Fix OpenApi spec

Co-authored-by: Zeegaan <nge@umbraco.dk>
This commit is contained in:
Kenn Jacobsen
2022-09-23 14:03:16 +02:00
committed by GitHub
parent 12a341f67d
commit c903c8a1a0
7 changed files with 163 additions and 1 deletions

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;
namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache;
public class CollectPublishedCacheController : PublishedCacheControllerBase
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
public CollectPublishedCacheController(IPublishedSnapshotService publishedSnapshotService)
=> _publishedSnapshotService = publishedSnapshotService;
[HttpPost("collect")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> Collect()
{
GC.Collect();
await _publishedSnapshotService.CollectAsync();
return Ok();
}
}

View File

@@ -0,0 +1,13 @@
using Microsoft.AspNetCore.Mvc;
using NSwag.Annotations;
using Umbraco.New.Cms.Web.Common.Routing;
namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache;
[ApiVersion("1.0")]
[ApiController]
[BackOfficeRoute("api/v{version:apiVersion}/published-cache")]
[OpenApiTag("PublishedCache")]
public class PublishedCacheControllerBase : ManagementApiControllerBase
{
}

View File

@@ -0,0 +1,22 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;
namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache;
public class RebuildPublishedCacheController : PublishedCacheControllerBase
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
public RebuildPublishedCacheController(IPublishedSnapshotService publishedSnapshotService)
=> _publishedSnapshotService = publishedSnapshotService;
[HttpPost("rebuild")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> Collect()
{
_publishedSnapshotService.Rebuild();
return await Task.FromResult(Ok());
}
}

View File

@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Cache;
using Umbraco.Extensions;
namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache;
public class ReloadPublishedCacheController : PublishedCacheControllerBase
{
private readonly DistributedCache _distributedCache;
public ReloadPublishedCacheController(DistributedCache distributedCache) => _distributedCache = distributedCache;
[HttpPost("reload")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
public async Task<ActionResult> Reload()
{
_distributedCache.RefreshAllPublishedSnapshot();
return await Task.FromResult(Ok());
}
}

View File

@@ -0,0 +1,19 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.PublishedCache;
namespace Umbraco.Cms.ManagementApi.Controllers.PublishedCache;
public class StatusPublishedCacheController : PublishedCacheControllerBase
{
private readonly IPublishedSnapshotStatus _publishedSnapshotStatus;
public StatusPublishedCacheController(IPublishedSnapshotStatus publishedSnapshotStatus)
=> _publishedSnapshotStatus = publishedSnapshotStatus;
[HttpGet("status")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(string), StatusCodes.Status200OK)]
public async Task<ActionResult<string>> Status()
=> await Task.FromResult(Ok(_publishedSnapshotStatus.GetStatus()));
}

View File

@@ -273,6 +273,65 @@
}
}
}
},
"/umbraco/api/v1/published-cache/collect": {
"post": {
"tags": [
"PublishedCache"
],
"operationId": "CollectPublishedCache_Collect",
"responses": {
"200": {
"description": ""
}
}
}
},
"/umbraco/api/v1/published-cache/rebuild": {
"post": {
"tags": [
"PublishedCache"
],
"operationId": "RebuildPublishedCache_Collect",
"responses": {
"200": {
"description": ""
}
}
}
},
"/umbraco/api/v1/published-cache/reload": {
"post": {
"tags": [
"PublishedCache"
],
"operationId": "ReloadPublishedCache_Reload",
"responses": {
"200": {
"description": ""
}
}
}
},
"/umbraco/api/v1/published-cache/status": {
"get": {
"tags": [
"PublishedCache"
],
"operationId": "StatusPublishedCache_Status",
"responses": {
"200": {
"description": "",
"content": {
"application/json": {
"schema": {
"type": "string"
}
}
}
}
}
}
}
},
"components": {
@@ -574,6 +633,9 @@
{
"name": "Server"
},
{
"name": "PublishedCache"
},
{
"name": "Profiling"
},

View File

@@ -28,7 +28,7 @@ public class OpenAPIContractTest : UmbracoTestServerTestBase
[Test]
public async Task Validate_OpenApi_Contract_is_implemented()
{
string[] keysToIgnore = { "servers" };
string[] keysToIgnore = { "servers", "x-generator" };
var officePath = GlobalSettings.GetBackOfficePath(HostingEnvironment);