Move localdb file management of PublishedSnapshotService into itself. (#15085)
* Move localdb file management of PublishedSnapshotService into itself. Added a way for the PublishedSnapshot service to clean up it's local files so (for example) Upgrade migrations have a reliable way of removing known invalid cache files without running into locking issues * Small rename to differentiate existing method from simple getter * Fix breaking change Long live default implementations 🎉 * Another breaking change fix --------- Co-authored-by: Sven Geusens <sge@umbraco.dk>
This commit is contained in:
committed by
Sven Geusens
parent
d2ff2ea46e
commit
c73b7f42d9
@@ -125,4 +125,8 @@ public interface IPublishedSnapshotService : IDisposable
|
||||
/// Cleans up unused snapshots
|
||||
/// </summary>
|
||||
Task CollectAsync();
|
||||
|
||||
void ResetLocalDb()
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +1,34 @@
|
||||
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Umbraco.Cms.Core.DependencyInjection;
|
||||
using Umbraco.Cms.Core.PublishedCache;
|
||||
using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_12_0_0;
|
||||
|
||||
public class ResetCache : MigrationBase
|
||||
{
|
||||
private readonly IHostingEnvironment _hostingEnvironment;
|
||||
private readonly IPublishedSnapshotService _publishedSnapshotService;
|
||||
|
||||
[Obsolete("Use ctor with all params - This will be removed in Umbraco 14.")]
|
||||
public ResetCache(IMigrationContext context, IHostingEnvironment hostingEnvironment)
|
||||
: base(context) =>
|
||||
: this(context, hostingEnvironment, StaticServiceProvider.Instance.GetRequiredService<IPublishedSnapshotService>())
|
||||
{
|
||||
}
|
||||
|
||||
public ResetCache(IMigrationContext context, IHostingEnvironment hostingEnvironment, IPublishedSnapshotService publishedSnapshotService)
|
||||
: base(context)
|
||||
{
|
||||
_hostingEnvironment = hostingEnvironment;
|
||||
_publishedSnapshotService = publishedSnapshotService;
|
||||
}
|
||||
|
||||
protected override void Migrate()
|
||||
{
|
||||
RebuildCache = true;
|
||||
var distCacheFolderAbsolutePath = Path.Combine(_hostingEnvironment.LocalTempPath, "DistCache");
|
||||
var nuCacheFolderAbsolutePath = Path.Combine(_hostingEnvironment.LocalTempPath, "NuCache");
|
||||
DeleteAllFilesInFolder(distCacheFolderAbsolutePath);
|
||||
DeleteAllFilesInFolder(nuCacheFolderAbsolutePath);
|
||||
_publishedSnapshotService.ResetLocalDb();
|
||||
}
|
||||
|
||||
private void DeleteAllFilesInFolder(string path)
|
||||
|
||||
@@ -70,6 +70,8 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
private long _mediaGen;
|
||||
private ContentStore _mediaStore = null!;
|
||||
|
||||
private string LocalFilePath => Path.Combine(_hostingEnvironment.LocalTempPath, "NuCache");
|
||||
|
||||
public PublishedSnapshotService(
|
||||
PublishedSnapshotServiceOptions options,
|
||||
ISyncBootStateAccessor syncBootStateAccessor,
|
||||
@@ -475,6 +477,22 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
return GetUid(_mediaStore, id);
|
||||
}
|
||||
|
||||
|
||||
public void ResetLocalDb()
|
||||
{
|
||||
_logger.LogInformation(
|
||||
"Resetting NuCache local db");
|
||||
var path = LocalFilePath;
|
||||
if (Directory.Exists(path) is false)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
MainDomRelease();
|
||||
Directory.Delete(path, true);
|
||||
MainDomRegister();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lazily populates the stores only when they are first requested
|
||||
/// </summary>
|
||||
@@ -603,7 +621,7 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
/// </remarks>
|
||||
private void MainDomRegister()
|
||||
{
|
||||
var path = GetLocalFilesPath();
|
||||
var path = GetAndEnsureLocalFilesPathExists();
|
||||
var localContentDbPath = Path.Combine(path, "NuCache.Content.db");
|
||||
var localMediaDbPath = Path.Combine(path, "NuCache.Media.db");
|
||||
|
||||
@@ -652,9 +670,9 @@ internal class PublishedSnapshotService : IPublishedSnapshotService
|
||||
}
|
||||
}
|
||||
|
||||
private string GetLocalFilesPath()
|
||||
private string GetAndEnsureLocalFilesPathExists()
|
||||
{
|
||||
var path = Path.Combine(_hostingEnvironment.LocalTempPath, "NuCache");
|
||||
var path = LocalFilePath;
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user