Skip to content

Commit

Permalink
Fix tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Jul 22, 2023
1 parent 00878c8 commit fe36a37
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,29 +128,30 @@ protected override async Task<object> EnrichResultAsync(CommandContext context,
{
var payload = await base.EnrichResultAsync(context, result, ct);

if (payload is IAssetEntity asset)
if (payload is not IAssetEntity asset)
{
if (result.IsChanged && context.Command is UploadAssetCommand)
return payload;
}

if (result.IsChanged && context.Command is UploadAssetCommand)
{
var tempFile = context.ContextId.ToString();
try
{
var tempFile = context.ContextId.ToString();
try
{
await assetFileStore.CopyAsync(tempFile, asset.AppId.Id, asset.AssetId, asset.FileVersion, null, ct);
}
catch (AssetAlreadyExistsException)
await assetFileStore.CopyAsync(tempFile, asset.AppId.Id, asset.AssetId, asset.FileVersion, null, ct);
}
catch (AssetAlreadyExistsException)
{
if (context.Command is not UpsertAsset)
{
if (context.Command is not UpsertAsset)
{
throw;
}
throw;
}

}
}

if (payload is not IEnrichedAssetEntity)
{
payload = await assetEnricher.EnrichAsync(asset, contextProvider.Context, ct);
}
if (payload is not IEnrichedAssetEntity)
{
payload = await assetEnricher.EnrichAsync(asset, contextProvider.Context, ct);
}

return payload;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@
// All rights reserved. Licensed under the MIT license.
// ==========================================================================

using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Channels;
using System.Threading.Tasks.Dataflow;
using Microsoft.Extensions.Logging;
using NodaTime;
using Squidex.Domain.Apps.Core.Apps;
Expand Down
5 changes: 3 additions & 2 deletions backend/src/Squidex.Domain.Apps.Entities/Tags/TagService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,12 @@ public async Task ClearAsync(
CancellationToken ct = default)
{
// Run batch first, because it is cheaper as it has less items.
var batches = persistenceFactory.Snapshots.ReadAllAsync(ct).Batch(500, ct).Buffered(2);
var batches = persistenceFactory.Snapshots.ReadAllAsync(ct).Batch(500, ct).Buffered(2, ct: ct);

await Parallel.ForEachAsync(batches, ct, async (batch, ct) =>
{
var jobs = batch.Where(x => x.Value.Clear()).Select(x => new SnapshotWriteJob<State>(x.Key, x.Value, x.Version));
// Convert to list for the tests, actually not needed.
var jobs = batch.Where(x => x.Value.Clear()).Select(x => new SnapshotWriteJob<State>(x.Key, x.Value, x.Version)).ToList();
await persistenceFactory.Snapshots.WriteManyAsync(jobs, ct);
});
Expand Down
1 change: 1 addition & 0 deletions backend/src/Squidex.Infrastructure/CollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static async IAsyncEnumerable<List<T>> Batch<T>(this IAsyncEnumerable<T>
await foreach (var item in source.WithCancellation(ct))
{
bucket ??= new List<T>(size);
bucket.Add(item);

if (bucket.Count == size)
{
Expand Down
2 changes: 1 addition & 1 deletion backend/src/Squidex.Infrastructure/Commands/Rebuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ private async Task InsertManyAsync<T, TState>(IAsyncEnumerable<DomainId> source,

using (localCache.StartContext())
{
// Run batch first, because it is cheaper.
// Run batch first, because it is cheaper as it has less items.
var batches = source.Where(handledIds.Add).Batch(batchSize, ct).Buffered(2, ct);

await Parallel.ForEachAsync(batches, ct, async (batch, ct) =>
Expand Down

0 comments on commit fe36a37

Please sign in to comment.