Skip to content

Commit

Permalink
fixes #590.
Browse files Browse the repository at this point in the history
  • Loading branch information
KevinJump committed Feb 28, 2024
1 parent ae5a631 commit c1f3980
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
28 changes: 19 additions & 9 deletions uSync.BackOffice/Extensions/uSyncActionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;

using Umbraco.Extensions;
Expand Down Expand Up @@ -29,35 +30,44 @@ public static int CountChanges(this IEnumerable<uSyncAction> actions)
/// </summary>
public static bool IsValidAction(this HandlerActions requestedAction, IEnumerable<string> actions)
=> requestedAction == HandlerActions.None ||
actions.Count() == 0 ||
actions.Count() == 0 ||
actions.InvariantContains("all") ||
actions.InvariantContains(requestedAction.ToString());

/// <summary>
/// Convert a list of actions into a summary list of actions, uses less cpu when people sync massive amounts of content.
/// </summary>
public static IEnumerable<uSyncAction> ConvertToSummary(this IEnumerable<uSyncAction> actions, bool strict)
public static IEnumerable<uSyncAction> ConvertToSummary(this IEnumerable<uSyncAction> actions, bool strict)
{
var summary = new List<uSyncAction>();

foreach(var items in actions.GroupBy(x => x.HandlerAlias))
foreach (var items in actions.GroupBy(x => x.HandlerAlias))
{
var fails = items.Where(x => !x.Success).ToList();

summary.Add(uSyncAction.SetAction(
success: true,
name: items.Key,
type: items.Key,
success: true,
name: items.Key,
type: items.Key,
change: Core.ChangeType.Information,
message: $"({items.CountChanges()}/{items.Count()} Changes) ({fails.Count} failures)")
);
);

if (!strict) summary.AddRange(fails);

}

return summary;
}

/// <summary>
/// try to find an action in the list based on key, and handler alias
/// </summary>
public static bool TryFindAction(this IEnumerable<uSyncAction> actions, Guid key, string handlerAlias, out uSyncAction action)
{
action = actions.FirstOrDefault(x => $"{x.key}_{x.HandlerAlias}" == $"{key}_{handlerAlias}", new uSyncAction { key = Guid.Empty });
return action.key != Guid.Empty;
}

}
}
8 changes: 3 additions & 5 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -573,15 +573,14 @@ private void PerformSecondPassImports(List<ImportedItem<TObject>> importedItems,
// if the second attempt has a message on it, add it to the first attempt.
if (!string.IsNullOrWhiteSpace(attempt.Message) || attempt.Details?.Any() == true)
{
uSyncAction action = actions.FirstOrDefault(x => $"{x.key}_{x.HandlerAlias}" == $"{itemKey}_{this.Alias}", new uSyncAction { key = Guid.Empty });
if (action.key != Guid.Empty)
if (actions.TryFindAction(itemKey, this.Alias, out var action))
{
actions.Remove(action);
action.Message += attempt.Message ?? "";

if (attempt.Details?.Any() == true)
{
var details = action.Details.ToList();
var details = action.Details?.ToList() ?? [];
details.AddRange(attempt.Details);
action.Details = details;
}
Expand All @@ -595,8 +594,7 @@ private void PerformSecondPassImports(List<ImportedItem<TObject>> importedItems,
}
else
{
uSyncAction action = actions.FirstOrDefault(x => $"{x.key}_{x.HandlerAlias}" == $"{itemKey}_{this.Alias}", new uSyncAction { key = Guid.Empty });
if (action.key != Guid.Empty)
if (actions.TryFindAction(itemKey, this.Alias, out var action))
{
actions.Remove(action);
action.Success = attempt.Success;
Expand Down

0 comments on commit c1f3980

Please sign in to comment.