Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use suppression of notifications if configured #611

Open
wants to merge 3 commits into
base: v13/main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 16 additions & 7 deletions uSync.BackOffice/Configuration/uSyncSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,26 @@ public class uSyncSettings

/// <summary>
/// turns of use of the Notifications.Supress method, so notifications
/// fire after every item is imported.
/// are suppressed during the import
/// </summary>
/// <remarks>
/// I am not sure this does what i think it does, it doesn't suppress
/// then fire at the end , it just suppresses them all.
///
/// until we have had time to look at this , we will leave this as
/// disabled by default so all notification messages fire.
/// this will result in no notifications being fired througout the import,
/// use this if you are comfortable with the risks
/// </remarks>
[DefaultValue("false")]
public bool DisableNotificationSuppression { get; set; } = false;
public bool EnableNotificationSuppression { get; set; } = false;

/// <summary>
/// suppress notifications by name
/// </summary>
/// <remarks>
/// This will suppress notifications by name (e.g ContentTreeChangeNotification)
/// These notifications will not fire during an uSync import.
///
/// You need to understand the consequences of notifications not firing on
/// other elements of Umbraco before setting this value.
/// </remarks>
public string[] SuppressNamedNotifications { get; set; } = [];

/// <summary>
/// trigger all the notifications in a background thread,
Expand Down
6 changes: 3 additions & 3 deletions uSync.BackOffice/Extensions/ScopeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ namespace uSync.BackOffice.Extensions;
internal static class ScopeExtensions
{
public static IDisposable SuppressScopeByConfig(this ICoreScope scope, uSyncConfigService configService)
=> configService.Settings.DisableNotificationSuppression
? new DummyDisposable()
: scope.Notifications.Suppress();
=> configService.Settings.EnableNotificationSuppression
? scope.Notifications.Suppress()
: new DummyDisposable();


public static ICoreScope CreateNotificationScope(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;
using Umbraco.Cms.Infrastructure.HostedServices;
using Umbraco.Extensions;

using uSync.BackOffice.Configuration;
using uSync.BackOffice.Services;
Expand Down Expand Up @@ -58,9 +59,15 @@ protected override void PublishScopedNotifications(IList<INotification> notifica

foreach (var items in groupedNotifications)
{
if (_uSyncConfig.Settings.SuppressNamedNotifications.InvariantContains(items.Key))
{
_logger.LogDebug("Suppressing {count} {name} notifications based on uSyncConfig", items.Count(), items.Key);
continue;
}

if (_uSyncConfig.Settings.BackgroundNotifications is true && _backgroundTaskQueue != null)
{
_logger.LogDebug("Pushed {count} notifications into background queue", items.Count());
_logger.LogDebug("Pushed {count} {name} notifications into background queue", items.Count(), items.Key);
_backgroundTaskQueue.QueueBackgroundWorkItem(
cancellationToken =>
{
Expand All @@ -75,6 +82,7 @@ protected override void PublishScopedNotifications(IList<INotification> notifica
}
else
{
_logger.LogDebug("Processing {count} {name} notifications", items.Count(), items.Key);
_updateCallback?.Invoke($"Processing {items.Key}s ({items.Count()})", 90, 100);
_eventAggregator.Publish(items);
}
Expand Down
2 changes: 2 additions & 0 deletions uSync.BackOffice/Services/uSyncService_Handlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public IEnumerable<uSyncAction> ImportHandler(string handlerAlias, uSyncImportOp
backgroundTaskQueue: _backgroundTaskQueue,
options.Callbacks?.Update);

using var supression = scope.SuppressScopeByConfig(_uSyncConfig);

var results = handlerPair.Handler.ImportAll(folders, handlerPair.Settings, options);

_logger.LogDebug("< Import Handler {handler}", handlerAlias);
Expand Down
8 changes: 6 additions & 2 deletions uSync.BackOffice/Services/uSyncService_Single.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ public IEnumerable<uSyncAction> ImportPartial(IList<OrderedNodeInfo> orderedNode

var index = options.PageNumber * options.PageSize;

using var scope = _scopeProvider.CreateNotificationScope(
using (var scope = _scopeProvider.CreateNotificationScope(
eventAggregator: _eventAggregator,
loggerFactory: _loggerFactory,
syncConfigService: _uSyncConfig,
syncEventService: _mutexService,
backgroundTaskQueue: _backgroundTaskQueue,
options.Callbacks?.Update);
options.Callbacks?.Update))
{
using var suppression = scope.SuppressScopeByConfig(_uSyncConfig);

try
{
foreach (var item in orderedNodes.Skip(options.PageNumber * options.PageSize).Take(options.PageSize))
Expand Down Expand Up @@ -209,6 +211,8 @@ public IEnumerable<uSyncAction> ImportPartialSecondPass(IEnumerable<uSyncAction>
backgroundTaskQueue: _backgroundTaskQueue,
options.Callbacks?.Update))
{
using var suppression = scope.SuppressScopeByConfig(_uSyncConfig);

try
{
foreach (var action in actions.Skip(options.PageNumber * options.PageSize).Take(options.PageSize))
Expand Down
Loading