Skip to content

Commit

Permalink
RebuildOnStartupHandler should not inject ExamineIndexRebuilder, but …
Browse files Browse the repository at this point in the history
…only the interface (#15465)
  • Loading branch information
bergmania authored Dec 18, 2023
1 parent 8ecc555 commit bf498b4
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ public static IUmbracoBuilder AddExamine(this IUmbracoBuilder builder)
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>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

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;
Expand Down
27 changes: 24 additions & 3 deletions src/Umbraco.Infrastructure/Examine/RebuildOnStartupHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -58,7 +79,7 @@ public void Handle(UmbracoRequestBeginNotification notification)
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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static IUmbracoBuilder AddTestServices(this IUmbracoBuilder builder, Test
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
Expand Down

0 comments on commit bf498b4

Please sign in to comment.