New IPublishedSnapshotStatus, reduces IPublishedSnapshotService

This commit is contained in:
Shannon
2020-12-21 17:41:12 +11:00
parent e8f5aa8ebc
commit c761fa0506
10 changed files with 146 additions and 117 deletions

View File

@@ -1,5 +1,6 @@
using System;
using System;
using System.Reflection.Metadata;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Core;
using Umbraco.Web.Cache;
@@ -8,43 +9,54 @@ using Umbraco.Web.PublishedCache;
namespace Umbraco.Web.BackOffice.Controllers
{
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
public class PublishedSnapshotCacheStatusController : UmbracoAuthorizedApiController
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IPublishedSnapshotStatus _publishedSnapshotStatus;
private readonly DistributedCache _distributedCache;
public PublishedSnapshotCacheStatusController(IPublishedSnapshotService publishedSnapshotService, DistributedCache distributedCache)
/// <summary>
/// Initializes a new instance of the <see cref="PublishedSnapshotCacheStatusController"/> class.
/// </summary>
public PublishedSnapshotCacheStatusController(
IPublishedSnapshotService publishedSnapshotService,
IPublishedSnapshotStatus publishedSnapshotStatus,
DistributedCache distributedCache)
{
_publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
_publishedSnapshotStatus = publishedSnapshotStatus;
_distributedCache = distributedCache;
}
/// <summary>
/// Rebuilds the Database cache
/// </summary>
[HttpPost]
public string RebuildDbCache()
{
_publishedSnapshotService.Rebuild();
return _publishedSnapshotService.GetStatus();
return _publishedSnapshotStatus.GetStatus();
}
/// <summary>
/// Gets a status report
/// </summary>
[HttpGet]
public string GetStatus()
{
return _publishedSnapshotService.GetStatus();
}
public string GetStatus() => _publishedSnapshotStatus.GetStatus();
/// <summary>
/// Cleans up unused snapshots
/// </summary>
[HttpGet]
public string Collect()
public async Task<string> Collect()
{
GC.Collect();
_publishedSnapshotService.Collect();
return _publishedSnapshotService.GetStatus();
await _publishedSnapshotService.CollectAsync();
return _publishedSnapshotStatus.GetStatus();
}
[HttpPost]
public void ReloadCache()
{
_distributedCache.RefreshAllPublishedSnapshot();
}
public void ReloadCache() => _distributedCache.RefreshAllPublishedSnapshot();
}
}

View File

@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Web.PublishedCache;
@@ -6,22 +6,22 @@ namespace Umbraco.Web.BackOffice.Controllers
{
public class PublishedStatusController : UmbracoAuthorizedApiController
{
private readonly IPublishedSnapshotService _publishedSnapshotService;
private readonly IPublishedSnapshotStatus _publishedSnapshotStatus;
public PublishedStatusController(IPublishedSnapshotService publishedSnapshotService)
public PublishedStatusController(IPublishedSnapshotStatus publishedSnapshotStatus)
{
_publishedSnapshotService = publishedSnapshotService ?? throw new ArgumentNullException(nameof(publishedSnapshotService));
_publishedSnapshotStatus = publishedSnapshotStatus ?? throw new ArgumentNullException(nameof(publishedSnapshotStatus));
}
[HttpGet]
public string GetPublishedStatusUrl()
{
if (!string.IsNullOrWhiteSpace(_publishedSnapshotService.StatusUrl))
if (!string.IsNullOrWhiteSpace(_publishedSnapshotStatus.StatusUrl))
{
return _publishedSnapshotService.StatusUrl;
return _publishedSnapshotStatus.StatusUrl;
}
throw new NotSupportedException("Not supported: " + _publishedSnapshotService.GetType().FullName);
throw new NotSupportedException("Not supported: " + _publishedSnapshotStatus.GetType().FullName);
}
}
}