RebuildOnStartupHandler should not inject ExamineIndexRebuilder, but only the interface (#15465)

This commit is contained in:
Bjarke Berg
2023-12-18 06:58:12 +01:00
committed by GitHub
parent 8ecc5552ab
commit bf498b411c
4 changed files with 29 additions and 5 deletions

View File

@@ -57,7 +57,9 @@ public static partial class UmbracoBuilderExtensions
builder.Services.AddUnique<IDeliveryApiContentIndexFieldDefinitionBuilder, DeliveryApiContentIndexFieldDefinitionBuilder>();
builder.Services.AddUnique<IDeliveryApiContentIndexHelper, DeliveryApiContentIndexHelper>();
builder.Services.AddSingleton<IDeliveryApiIndexingHandler, DeliveryApiIndexingHandler>();
builder.Services.AddSingleton<ExamineIndexRebuilder>();
builder.Services.AddSingleton<ExamineIndexRebuilder>(); //TODO remove in Umbraco 15. Only the interface should be in the service provider
builder.Services.AddUnique<IDeliveryApiCompositeIdHandler, DeliveryApiCompositeIdHandler>();
builder.AddNotificationHandler<ContentCacheRefresherNotification, ContentIndexingNotificationHandler>();

View File

@@ -10,6 +10,7 @@ using Umbraco.Cms.Infrastructure.HostedServices;
namespace Umbraco.Cms.Infrastructure.Examine;
[Obsolete("This will be removed in Umbraco 15. Use IIndexRebuilder instead.")] // Main reason for this is to remove it form the service container. Maybe even make this internal
public class ExamineIndexRebuilder : IIndexRebuilder
{
private readonly IBackgroundTaskQueue _backgroundTaskQueue;

View File

@@ -24,17 +24,38 @@ public sealed class RebuildOnStartupHandler : INotificationHandler<UmbracoReques
private static bool _isReady;
private static bool _isReadSet;
private static object? _isReadyLock;
private readonly ExamineIndexRebuilder _backgroundIndexRebuilder;
private readonly IRuntimeState _runtimeState;
private readonly ISyncBootStateAccessor _syncBootStateAccessor;
private readonly IIndexRebuilder _indexRebuilder;
[Obsolete("Use non-obsolete constructor. This is scheduled for removal in Umbraco 15.")]
public RebuildOnStartupHandler(
ISyncBootStateAccessor syncBootStateAccessor,
ExamineIndexRebuilder backgroundIndexRebuilder,
IRuntimeState runtimeState)
: this(syncBootStateAccessor, (IIndexRebuilder) backgroundIndexRebuilder, runtimeState)
{
}
[Obsolete("Use non-obsolete constructor. This is scheduled for removal in Umbraco 15.")]
public RebuildOnStartupHandler(
ISyncBootStateAccessor syncBootStateAccessor,
ExamineIndexRebuilder backgroundIndexRebuilder,
IIndexRebuilder indexRebuilder,
IRuntimeState runtimeState)
: this(syncBootStateAccessor, indexRebuilder, runtimeState)
{
}
public RebuildOnStartupHandler(
ISyncBootStateAccessor syncBootStateAccessor,
IIndexRebuilder indexRebuilder,
IRuntimeState runtimeState)
{
_syncBootStateAccessor = syncBootStateAccessor;
_backgroundIndexRebuilder = backgroundIndexRebuilder;
_indexRebuilder = indexRebuilder;
_runtimeState = runtimeState;
}
@@ -58,7 +79,7 @@ public sealed class RebuildOnStartupHandler : INotificationHandler<UmbracoReques
SyncBootState bootState = _syncBootStateAccessor.GetSyncBootState();
// if it's not a cold boot, only rebuild empty ones
_backgroundIndexRebuilder.RebuildIndexes(
_indexRebuilder.RebuildIndexes(
bootState != SyncBootState.ColdBoot,
TimeSpan.FromMinutes(1));

View File

@@ -46,7 +46,7 @@ public static class UmbracoBuilderExtensions
builder.Services.AddUnique(Mock.Of<IUmbracoBootPermissionChecker>());
builder.Services.AddUnique(testHelper.MainDom);
builder.Services.AddUnique<ExamineIndexRebuilder, TestBackgroundIndexRebuilder>();
builder.Services.AddUnique<IIndexRebuilder, TestBackgroundIndexRebuilder>();
builder.Services.AddUnique(factory => Mock.Of<IRuntimeMinifier>());
// we don't want persisted nucache files in tests