From aa23fd071c6eb0aa3a8f66328034c1cd110c4db1 Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Sun, 10 Nov 2024 18:36:58 +0100 Subject: [PATCH] Use streaming endpoint for contents. --- cli/Squidex.CLI/Directory.Build.props | 2 +- .../Sync/Contents/ContentsSynchronizer.cs | 13 +++++++++++-- .../Sync/Schemas/SchemasSynchronizer.cs | 2 +- .../Commands/Implementation/Sync/SyncOptions.cs | 2 ++ .../Sync/Workflows/WorkflowsSynchronizer.cs | 2 +- cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs | 10 +++++++++- 6 files changed, 25 insertions(+), 6 deletions(-) diff --git a/cli/Squidex.CLI/Directory.Build.props b/cli/Squidex.CLI/Directory.Build.props index 3443a374..7c177b0f 100644 --- a/cli/Squidex.CLI/Directory.Build.props +++ b/cli/Squidex.CLI/Directory.Build.props @@ -15,6 +15,6 @@ Squidex HeadlessCMS true snupkg - 13.4 + 13.6 diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs index aff3cd56..99f889cb 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs @@ -77,7 +77,7 @@ Task SaveAsync() }); } - await client.GetAllAsync(async content => + async Task HandleContentAsync(DynamicContent content) { if (content.LastModified < options.MaxAgeDate) { @@ -96,7 +96,16 @@ await client.GetAllAsync(async content => contents.Clear(); contentBatch++; } - }, context: context); + } + + if (options.StreamContents) + { + await client.StreamAllAsync(HandleContentAsync, context: context); + } + else + { + await client.GetAllAsync(HandleContentAsync, context: context); + } if (contents.Count > 0) { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs index ba36f5fb..2a39bcb9 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Schemas/SchemasSynchronizer.cs @@ -107,7 +107,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s { foreach (var name in current.Items.Select(x => x.Name)) { - if (createModels.All(x => x.Name != name)) + if (createModels.TrueForAll(x => x.Name != name)) { await log.DoSafeAsync($"Schema {name} deleting", async () => { diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncOptions.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncOptions.cs index 8c36f046..6562978c 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncOptions.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/SyncOptions.cs @@ -19,6 +19,8 @@ public sealed class SyncOptions public bool Recreate { get; set; } + public bool StreamContents { get; set; } + public bool UpdateCurrentClient { get; set; } public DateTimeOffset MaxAgeDate { get; set; } diff --git a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs index 794b810a..a6266180 100644 --- a/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs +++ b/cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Workflows/WorkflowsSynchronizer.cs @@ -101,7 +101,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s { foreach (var (name, workflow) in workflowsByName.ToList()) { - if (models.All(x => x.Name == name)) + if (models.TrueForAll(x => x.Name == name)) { await log.DoSafeAsync($"Workflow '{name}' deleting", async () => { diff --git a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs index 5ad6067d..4598ffef 100644 --- a/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs +++ b/cli/Squidex.CLI/Squidex.CLI/Commands/App_Sync.cs @@ -156,6 +156,9 @@ public sealed class OutArguments : AppArguments [Option('t', "targets", Description = "The targets to sync, e.g. ‘sync out -t contents -t schemas’. Use 'sync targets' to view all targets.")] public string[] Targets { get; set; } + [Option("stream-contents", Description = "Use the new streaming API for contents.")] + public bool StreamContents { get; set; } + [Option("max-age", Description = "Content & assets created or last modified within time span defined.")] public TimeSpan? MaxAge { get; set; } @@ -164,7 +167,12 @@ public sealed class OutArguments : AppArguments public SyncOptions ToOptions() { - return new SyncOptions { Targets = Targets, MaxAgeDate = GetMaxAgeDate() }; + return new SyncOptions + { + Targets = Targets, + MaxAgeDate = GetMaxAgeDate(), + StreamContents = StreamContents + }; } public sealed class Validator : AbstractValidator