Skip to content

Commit 8693e19

Browse files
Run multiple batches.
1 parent a9c77e4 commit 8693e19

File tree

3 files changed

+55
-32
lines changed

3 files changed

+55
-32
lines changed

cli/Squidex.CLI/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
<PackageTags>Squidex HeadlessCMS</PackageTags>
1616
<PublishRepositoryUrl>true</PublishRepositoryUrl>
1717
<SymbolPackageFormat>snupkg</SymbolPackageFormat>
18-
<Version>11.0</Version>
18+
<Version>11.1</Version>
1919
</PropertyGroup>
2020
</Project>

cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Assets/AssetsSynchronizer.cs

Lines changed: 49 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -131,53 +131,72 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
131131
await uploader.CompleteAsync();
132132
}
133133

134-
var request = new BulkUpdateAssetsDto();
134+
// Use separate batches to not cause issues with older Squidex version.
135+
var annotateBatch = new BulkUpdateAssetsDto
136+
{
137+
Jobs = new List<BulkUpdateAssetsJobDto>()
138+
};
135139

136140
foreach (var asset in model.Assets)
137141
{
138-
var parentId = await sync.Folders.GetIdAsync(asset.FolderPath);
139-
140-
request.Jobs.Add(asset.ToMove(parentId));
141-
request.Jobs.Add(asset.ToAnnotate());
142+
annotateBatch.Jobs.Add(asset.ToAnnotate());
142143
}
143144

144-
var assetIndex = 0;
145+
await ExecuteBatchAsync(session, batchIndex, model, annotateBatch, "Annotating");
145146

146-
var results = await session.Client.Assets.BulkUpdateAssetsAsync(request);
147+
var moveBatch = new BulkUpdateAssetsDto
148+
{
149+
Jobs = new List<BulkUpdateAssetsJobDto>()
150+
};
147151

148152
foreach (var asset in model.Assets)
149153
{
150-
// We create wo commands per asset.
151-
var result1 = results.FirstOrDefault(x => x.JobIndex == (assetIndex * 2));
152-
var result2 = results.FirstOrDefault(x => x.JobIndex == (assetIndex * 2) + 1);
153-
154-
log.StepStart($"Upserting #{batchIndex}/{assetIndex}");
155-
156-
if (result1?.Error != null)
157-
{
158-
log.StepFailed(result1.Error.ToString());
159-
}
160-
else if (result2?.Error != null)
161-
{
162-
log.StepFailed(result2.Error.ToString());
163-
}
164-
else if (result1?.Id != null && result2?.Id != null)
165-
{
166-
log.StepSuccess();
167-
}
168-
else
169-
{
170-
log.StepSkipped("Unknown Reason");
171-
}
154+
var parentId = await sync.Folders.GetIdAsync(asset.FolderPath);
172155

173-
assetIndex++;
156+
moveBatch.Jobs.Add(asset.ToMove(parentId));
174157
}
158+
159+
await ExecuteBatchAsync(session, batchIndex, model, moveBatch, "Moving");
175160
}
176161

177162
batchIndex++;
178163
}
179164
}
180165

166+
private async Task ExecuteBatchAsync(ISession session, int batchIndex, AssetsModel model, BulkUpdateAssetsDto request, string name)
167+
{
168+
var index = 0;
169+
var results = await session.Client.Assets.BulkUpdateAssetsAsync(request);
170+
171+
foreach (var asset in model.Assets)
172+
{
173+
// We create wo commands per asset.
174+
var result1 = results.FirstOrDefault(x => x.JobIndex == (index * 2));
175+
var result2 = results.FirstOrDefault(x => x.JobIndex == (index * 2) + 1);
176+
177+
log.StepStart($"{name} #{batchIndex}/{index}");
178+
179+
if (result1?.Error != null)
180+
{
181+
log.StepFailed(result1.Error.ToString());
182+
}
183+
else if (result2?.Error != null)
184+
{
185+
log.StepFailed(result2.Error.ToString());
186+
}
187+
else if (result1?.Id != null && result2?.Id != null)
188+
{
189+
log.StepSuccess();
190+
}
191+
else
192+
{
193+
log.StepSkipped("Unknown Reason");
194+
}
195+
196+
index++;
197+
}
198+
}
199+
181200
private static IEnumerable<IFile> GetFiles(IFileSystem fs)
182201
{
183202
foreach (var file in fs.GetFiles(new FilePath("assets"), ".json"))

cli/Squidex.CLI/Squidex.CLI.Core/Commands/Implementation/Sync/Contents/ContentsSynchronizer.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
125125

126126
var mapper = new Extensions.Mapper(session.Url, session.App, options.Languages);
127127

128+
var batchIndex = 0;
129+
128130
foreach (var (file, model) in models)
129131
{
130132
if (model?.Contents?.Count > 0)
@@ -151,7 +153,7 @@ public async Task ImportAsync(ISyncService sync, SyncOptions options, ISession s
151153
{
152154
var result = results.Find(x => x.JobIndex == contentIndex);
153155

154-
log.StepStart($"Upserting #{contentIndex}");
156+
log.StepStart($"Upserting #{batchIndex}/{contentIndex}");
155157

156158
if (result?.Error != null)
157159
{
@@ -183,6 +185,8 @@ await log.DoSafeAsync($"Saving {file.Name}", async () =>
183185
});
184186
}
185187
}
188+
189+
batchIndex++;
186190
}
187191
}
188192

0 commit comments

Comments
 (0)