Skip to content
Merged
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
15 changes: 15 additions & 0 deletions uSync.BackOffice/Models/SyncMergeOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using uSync.BackOffice.SyncHandlers.Interfaces;

namespace uSync.BackOffice.Models;

public class SyncMergeOptions

Check warning on line 5 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions'

Check warning on line 5 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions'

Check warning on line 5 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions'
{
public SyncMergeOptions() { }

Check warning on line 7 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.SyncMergeOptions()'

Check warning on line 7 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.SyncMergeOptions()'

Check warning on line 7 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.SyncMergeOptions()'

public SyncMergeOptions(SyncUpdateCallback? callback)

Check warning on line 9 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.SyncMergeOptions(SyncUpdateCallback?)'

Check warning on line 9 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.SyncMergeOptions(SyncUpdateCallback?)'
{
UpdateCallback = callback;
}

public SyncUpdateCallback? UpdateCallback { get; set; }

Check warning on line 14 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.UpdateCallback'

Check warning on line 14 in uSync.BackOffice/Models/SyncMergeOptions.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncMergeOptions.UpdateCallback'
}
2 changes: 1 addition & 1 deletion uSync.BackOffice/Services/SyncService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@


#region Importing
static SemaphoreSlim _importSemaphoreLock = new SemaphoreSlim(1, 1);
static readonly SemaphoreSlim _importSemaphoreLock = new SemaphoreSlim(1, 1);

/// <inheritdoc/>>
public async Task<IEnumerable<uSyncAction>> StartupImportAsync(string[] folders, bool force, SyncHandlerOptions handlerOptions, uSyncCallbacks? callbacks = null)
Expand Down Expand Up @@ -239,7 +239,7 @@
return (await handlerConfig.Handler.ImportAsync(action.FileName, handlerConfig.Settings, true)).FirstOrDefault();
}

public async Task<uSyncAction> ImportSingleItemAsync(Guid key, string handlerAlias)

Check warning on line 242 in uSync.BackOffice/Services/SyncService.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncService.ImportSingleItemAsync(Guid, string)'

Check warning on line 242 in uSync.BackOffice/Services/SyncService.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncService.ImportSingleItemAsync(Guid, string)'
{
var handlerConfig = _handlerFactory.GetValidHandler(handlerAlias);
if (handlerConfig is null) return uSyncAction.Fail("Unknown", handlerAlias, "Unknown", ChangeType.Fail, $"Could not find handler with alias {handlerAlias}", new KeyNotFoundException(handlerAlias));
Expand Down
7 changes: 4 additions & 3 deletions uSync.BackOffice/SyncHandlers/Handlers/LanguageHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Umbraco.Extensions;

using uSync.BackOffice.Configuration;
using uSync.BackOffice.Models;
using uSync.BackOffice.Services;
using uSync.BackOffice.SyncHandlers.Interfaces;
using uSync.BackOffice.SyncHandlers.Models;
Expand Down Expand Up @@ -72,8 +73,8 @@ protected override string GetItemPath(ILanguage item, bool useGuid, bool isFlat)
/// <summary>
/// order the merged items, making sure the default language is first.
/// </summary>
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders)
=> [.. (await base.GetMergedItemsAsync(folders)).OrderBy(x => x.Node.Element("IsDefault").ValueOrDefault(false) ? 0 : 1)];
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders, SyncMergeOptions options)
=> [.. (await base.GetMergedItemsAsync(folders, options)).OrderBy(x => x.Node.Element("IsDefault").ValueOrDefault(false) ? 0 : 1)];

/// <summary>
/// ensure we import the 'default' language first, so we don't get errors doing it.
Expand Down Expand Up @@ -162,7 +163,7 @@ protected override async Task CleanUpAsync(ILanguage item, string newFile, strin
}
}

private static ConcurrentDictionary<string, string> _newLanguages = new();
private readonly static ConcurrentDictionary<string, string> _newLanguages = new();

/// <inheritdoc/>
public override async Task HandleAsync(SavingNotification<ILanguage> notification, CancellationToken cancellationToken)
Expand Down
4 changes: 2 additions & 2 deletions uSync.BackOffice/SyncHandlers/Handlers/TemplateHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public TemplateHandler(
}

/// <inheritdoc/>
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders)
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders, SyncMergeOptions options)
{
var items = await base.GetMergedItemsAsync(folders);
var items = await base.GetMergedItemsAsync(folders, options);
try
{
var results = new List<OrderedNodeInfo>();
Expand Down
13 changes: 11 additions & 2 deletions uSync.BackOffice/SyncHandlers/SyncHandlerContainerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,17 @@ protected override bool DoItemsMatch(XElement node, TObject item)
/// <summary>
/// Get merged items from a collection of folders.
/// </summary>
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders)
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders, SyncMergeOptions options)
{
var items = await base.GetMergedItemsAsync(folders);
options.UpdateCallback?.Invoke("Order: Loading files from disk", 1, 5);

var items = await base.GetMergedItemsAsync(folders, options);

options.UpdateCallback?.Invoke("Order: Checking for duplicates", 2, 5);
CheckForDuplicates(items);

options.UpdateCallback?.Invoke("Order: Sorting items", 3, 5);

var nodes = items.DistinctBy(x => x.Key).ToDictionary(k => k.Key);
var renames = nodes.Where(x => x.Value.Node.IsEmptyItem()).Select(x => x.Value);
var graph = new List<GraphEdge<Guid>>();
Expand All @@ -258,12 +263,16 @@ protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsyn

var results = new List<OrderedNodeInfo>(sortedList.Count);

options.UpdateCallback?.Invoke("Order: Building sorted list", 4, 5);

foreach (var key in sortedList)
{
if (nodes.TryGetValue(key, out OrderedNodeInfo? value) && value is not null)
results.Add(value);
}

options?.UpdateCallback?.Invoke("Order: Adding actions", 5, 5);

if (renames.Any())
{
results.RemoveAll(x => renames.Any(r => r.Key == x.Key));
Expand Down
5 changes: 3 additions & 2 deletions uSync.BackOffice/SyncHandlers/SyncHandlerLevelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Umbraco.Extensions;

using uSync.BackOffice.Configuration;
using uSync.BackOffice.Models;
using uSync.BackOffice.Services;
using uSync.Core;

Expand Down Expand Up @@ -48,8 +49,8 @@ protected SyncHandlerLevelBase(
/// as we are already loading everything to merge, it doesn't
/// then cost us much to sort them when we have to.
/// </remarks>
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders)
=> [.. (await base.GetMergedItemsAsync(folders)).OrderBy(x => x.Level)];
protected override async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders, SyncMergeOptions options)
=> [.. (await base.GetMergedItemsAsync(folders, options)).OrderBy(x => x.Level)];

/// <inheritdoc/>
override protected string GetItemPath(TObject item, bool useGuid, bool isFlat)
Expand Down
23 changes: 14 additions & 9 deletions uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@

options.Callbacks?.Update?.Invoke("Calculating import order", 1, 9);

var items = await GetMergedItemsAsync(folders);
var items = await GetMergedItemsAsync(folders, new SyncMergeOptions(options.Callbacks?.Update));

options.Callbacks?.Update?.Invoke($"Processing {items.Count} items", 2, 9);

Expand Down Expand Up @@ -327,17 +327,22 @@
/// <param name="folders"></param>
/// <returns></returns>
public async Task<IReadOnlyList<OrderedNodeInfo>> FetchAllNodesAsync(string[] folders)
=> await GetMergedItemsAsync(folders);
=> await GetMergedItemsAsync(folders, new SyncMergeOptions());

/// <summary>
/// method to get the merged folders, handlers that care about orders should override this.
/// </summary>
protected virtual async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders)

protected virtual async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders, SyncMergeOptions options)

Check warning on line 333 in uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncHandlerRoot<TObject, TContainer>.GetMergedItemsAsync(string[], SyncMergeOptions)'

Check warning on line 333 in uSync.BackOffice/SyncHandlers/SyncHandlerRoot.cs

View workflow job for this annotation

GitHub Actions / build-project

Missing XML comment for publicly visible type or member 'SyncHandlerRoot<TObject, TContainer>.GetMergedItemsAsync(string[], SyncMergeOptions)'
{
var baseTracker = trackers.FirstOrDefault() as ISyncTrackerBase;
return [.. (await syncFileService.MergeFoldersAsync(folders, uSyncConfig.Settings.DefaultExtension, baseTracker))];
}

/// <summary>
/// method to get the merged folders, handlers that care about orders should override this.
/// </summary>
[Obsolete("Use GetMergedItemsAsync with SyncMergeOptions will be removed in v18")]
protected virtual async Task<IReadOnlyList<OrderedNodeInfo>> GetMergedItemsAsync(string[] folders)
=> await GetMergedItemsAsync(folders, new SyncMergeOptions());

/// <summary>
/// given a file path, will give you the merged values across all folders.
/// </summary>
Expand Down Expand Up @@ -1006,9 +1011,9 @@

var cacheKey = PrepCaches();

callback?.Invoke("Organizing import structure", 1, 3);
callback?.Invoke("Calculating order", 1, 3);

var items = await GetMergedItemsAsync(folders);
var items = await GetMergedItemsAsync(folders, new SyncMergeOptions(callback));
var options = new uSyncImportOptions();

int count = 0;
Expand Down Expand Up @@ -2008,7 +2013,7 @@
public async Task<XElement?> TryFindItemNodeAsync(Guid key)
{
var folders = GetDefaultHandlerFolders();
var items = await GetMergedItemsAsync(folders);
var items = await GetMergedItemsAsync(folders, new SyncMergeOptions());

foreach (var item in items)
{
Expand Down
Loading