From 21bcad84b2bc5372b75bfacbe34d95116b65dc4d Mon Sep 17 00:00:00 2001 From: Sebastian Stehle Date: Tue, 25 May 2021 16:49:10 +0200 Subject: [PATCH] CancellationToken --- .../Scripting/ExecutionContext.cs | 3 +- .../Scripting/IScriptEngine.cs | 5 +- .../Scripting/JintScriptEngine.cs | 108 ++++++++++-------- .../Assets/MongoAssetFolderRepository.cs | 18 +-- ...ongoAssetFolderRepository_SnapshotStore.cs | 5 +- .../Assets/MongoAssetRepository.cs | 50 ++++---- .../MongoAssetRepository_SnapshotStore.cs | 5 +- .../Contents/MongoContentCollection.cs | 58 ++++++---- .../Contents/MongoContentRepository.cs | 53 +++++---- .../MongoContentRepository_SnapshotStore.cs | 3 +- .../Contents/Operations/Extensions.cs | 6 +- .../Contents/Operations/OperationBase.cs | 2 +- .../Contents/Operations/QueryAsStream.cs | 2 +- .../Contents/Operations/QueryById.cs | 6 +- .../Contents/Operations/QueryByIds.cs | 11 +- .../Contents/Operations/QueryByQuery.cs | 30 ++--- .../Contents/Operations/QueryReferences.cs | 8 +- .../Contents/Operations/QueryReferrers.cs | 9 +- .../Contents/Operations/QueryScheduled.cs | 7 +- .../FullText/MongoTextIndex.cs | 3 +- .../History/MongoHistoryEventRepository.cs | 3 +- .../Rules/MongoRuleEventRepository.cs | 19 +-- .../Rules/MongoRuleStatisticsCollection.cs | 8 +- .../Apps/AppSettingsSearchSource.cs | 6 +- .../Apps/DefaultAppImageStore.cs | 6 +- .../Apps/DefaultAppLogStore.cs | 3 +- .../Assets/AssetsSearchSource.cs | 6 +- .../Assets/DefaultAssetFileStore.cs | 15 ++- .../DomainObject/AssetCommandMiddleware.cs | 2 +- .../Assets/DomainObject/Guards/GuardAsset.cs | 4 +- .../Assets/IAssetEnricher.cs | 7 +- .../Assets/IAssetQueryService.cs | 17 +-- .../Assets/Queries/AssetEnricher.cs | 16 ++- .../Assets/Queries/AssetQueryService.cs | 66 ++++++----- .../Assets/RebuildFiles.cs | 75 ++++++++++++ .../Assets/RecursiveDeleter.cs | 4 +- .../Repositories/IAssetFolderRepository.cs | 7 +- .../Assets/Repositories/IAssetRepository.cs | 16 +-- .../Backup/BackupGrain.cs | 8 +- .../Contents/ContentSchedulerGrain.cs | 4 +- .../Contents/ContentsSearchSource.cs | 6 +- .../Guards/ValidationExtensions.cs | 2 +- .../Contents/IContentQueryService.cs | 9 +- .../Contents/Queries/ContentEnricher.cs | 20 ++-- .../Contents/Queries/ContentQueryService.cs | 37 +++--- .../Contents/Queries/IContentEnricher.cs | 5 +- .../Contents/Queries/IContentEnricherStep.cs | 5 +- .../Contents/Queries/Steps/ConvertData.cs | 25 ++-- .../Queries/Steps/EnrichForCaching.cs | 9 +- .../Queries/Steps/EnrichWithSchema.cs | 6 +- .../Queries/Steps/EnrichWithWorkflows.cs | 6 +- .../Contents/Queries/Steps/ResolveAssets.cs | 11 +- .../Queries/Steps/ResolveReferences.cs | 16 ++- .../Contents/Queries/Steps/ScriptContent.cs | 11 +- .../Repositories/IContentRepository.cs | 18 +-- .../Validation/DependencyValidatorsFactory.cs | 8 +- .../Repositories/IRuleEventRepository.cs | 6 +- .../Schemas/SchemasSearchSource.cs | 4 +- .../Search/ISearchManager.cs | 3 +- .../Search/ISearchSource.cs | 3 +- .../Search/SearchManager.cs | 11 +- .../MongoRoleStore.cs | 5 +- .../MongoUserStore.cs | 5 +- .../EventSourcing/MongoEventStore.cs | 3 +- .../Log/MongoRequestLogRepository.cs | 3 +- .../MongoDb/MongoRepositoryBase.cs | 5 +- .../UsageTracking/MongoUsageRepository.cs | 5 +- .../Assets/AssetContentController.cs | 10 +- .../Assets/AssetFoldersController.cs | 4 +- .../Controllers/Assets/AssetsController.cs | 6 +- .../Contents/ContentsController.cs | 16 +-- .../Controllers/Search/SearchController.cs | 2 +- .../Apps/AppSettingsSearchSourceTests.cs | 50 ++++---- .../Assets/AssetsFluidExtensionTests.cs | 5 +- .../Assets/AssetsJintExtensionTests.cs | 5 +- .../Assets/AssetsSearchSourceTests.cs | 9 +- .../Assets/BackupAssetsTests.cs | 4 +- .../AssetCommandMiddlewareTests.cs | 10 +- .../DomainObject/AssetDomainObjectTests.cs | 9 +- .../AssetFolderDomainObjectTests.cs | 3 +- .../Guards/GuardAssetFolderTests.cs | 13 ++- .../DomainObject/Guards/GuardAssetTests.cs | 8 +- .../Assets/Queries/AssetEnricherTests.cs | 12 +- .../Assets/Queries/AssetQueryServiceTests.cs | 45 ++++---- .../Assets/RecursiveDeleterTests.cs | 7 +- .../Contents/BackupContentsTests.cs | 2 +- .../Contents/ContentsSearchSourceTests.cs | 11 +- .../ContentCommandMiddlewareTests.cs | 7 +- .../DomainObject/ContentDomainObjectTests.cs | 79 ++++++------- ...ontentsBulkUpdateCommandMiddlewareTests.cs | 7 +- .../Contents/GraphQL/GraphQLQueriesTests.cs | 43 +++---- .../Contents/Queries/ContentEnricherTests.cs | 30 ++--- .../Queries/ContentQueryServiceTests.cs | 31 ++--- .../Contents/Queries/ConvertDataTests.cs | 15 +-- .../Contents/Queries/EnrichForCachingTests.cs | 4 +- .../Contents/Queries/EnrichWithSchemaTests.cs | 6 +- .../Queries/EnrichWithWorkflowsTests.cs | 18 +-- .../Contents/Queries/ResolveAssetsTests.cs | 25 ++-- .../Queries/ResolveReferencesTests.cs | 25 ++-- .../Contents/Queries/ScriptContentTests.cs | 15 +-- .../Contents/ReferencesFluidExtensionTests.cs | 5 +- .../Contents/ReferencesJintExtensionTests.cs | 5 +- .../Rules/Queries/RuleEnricherTests.cs | 3 +- .../Schemas/SchemasSearchSourceTests.cs | 8 +- .../Search/SearchManagerTests.cs | 17 +-- 105 files changed, 882 insertions(+), 623 deletions(-) create mode 100644 backend/src/Squidex.Domain.Apps.Entities/Assets/RebuildFiles.cs diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ExecutionContext.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ExecutionContext.cs index acd08d133..102227952 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ExecutionContext.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/ExecutionContext.cs @@ -40,7 +40,8 @@ namespace Squidex.Domain.Apps.Core.Scripting completion?.Invoke(exception); } - public ExecutionContext ExtendAsync(IEnumerable extensions, Func completion, CancellationToken ct) + public ExecutionContext ExtendAsync(IEnumerable extensions, Func completion, + CancellationToken ct) { CancellationToken = ct; diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/IScriptEngine.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/IScriptEngine.cs index 7821db791..7eca9c6a7 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/IScriptEngine.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/IScriptEngine.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Contents; using Squidex.Infrastructure.Json.Objects; @@ -13,9 +14,9 @@ namespace Squidex.Domain.Apps.Core.Scripting { public interface IScriptEngine { - Task ExecuteAsync(ScriptVars vars, string script, ScriptOptions options = default); + Task ExecuteAsync(ScriptVars vars, string script, ScriptOptions options = default, CancellationToken ct = default); - Task TransformAsync(ScriptVars vars, string script, ScriptOptions options = default); + Task TransformAsync(ScriptVars vars, string script, ScriptOptions options = default, CancellationToken ct = default); IJsonValue Execute(ScriptVars vars, string script, ScriptOptions options = default); diff --git a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs index c354c6700..087fb3f4d 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Operations/Scripting/JintScriptEngine.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -68,90 +68,98 @@ namespace Squidex.Domain.Apps.Core.Scripting this.extensions = extensions?.ToArray() ?? Array.Empty(); } - public async Task ExecuteAsync(ScriptVars vars, string script, ScriptOptions options = default) + public async Task ExecuteAsync(ScriptVars vars, string script, ScriptOptions options = default, + CancellationToken ct = default) { Guard.NotNull(vars, nameof(vars)); Guard.NotNullOrEmpty(script, nameof(script)); using (var cts = new CancellationTokenSource(ActualTimeoutExecution)) { - var tcs = new TaskCompletionSource(); - - using (cts.Token.Register(() => tcs.TrySetCanceled())) + using (var combined = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, ct)) { - var context = - CreateEngine(options) - .Extend(vars, options) - .Extend(extensions) - .ExtendAsync(extensions, tcs.TrySetException, cts.Token); + var tcs = new TaskCompletionSource(); - context.Engine.SetValue("complete", new Action(value => + using (combined.Token.Register(() => tcs.TrySetCanceled())) { - tcs.TrySetResult(JsonMapper.Map(value)); - })); + var context = + CreateEngine(options) + .Extend(vars, options) + .Extend(extensions) + .ExtendAsync(extensions, tcs.TrySetException, combined.Token); - Execute(context.Engine, script); + context.Engine.SetValue("complete", new Action(value => + { + tcs.TrySetResult(JsonMapper.Map(value)); + })); - if (!context.IsAsync) - { - tcs.TrySetResult(JsonMapper.Map(context.Engine.GetCompletionValue())); - } + Execute(context.Engine, script); - return await tcs.Task; + if (!context.IsAsync) + { + tcs.TrySetResult(JsonMapper.Map(context.Engine.GetCompletionValue())); + } + + return await tcs.Task; + } } } } - public async Task TransformAsync(ScriptVars vars, string script, ScriptOptions options = default) + public async Task TransformAsync(ScriptVars vars, string script, ScriptOptions options = default, + CancellationToken ct = default) { Guard.NotNull(vars, nameof(vars)); Guard.NotNullOrEmpty(script, nameof(script)); using (var cts = new CancellationTokenSource(ActualTimeoutExecution)) { - var tcs = new TaskCompletionSource(); - - using (cts.Token.Register(() => tcs.TrySetCanceled())) + using (var combined = CancellationTokenSource.CreateLinkedTokenSource(cts.Token, ct)) { - var context = - CreateEngine(options) - .Extend(vars, options) - .Extend(extensions) - .ExtendAsync(extensions, tcs.TrySetException, cts.Token); + var tcs = new TaskCompletionSource(); - context.Engine.SetValue("complete", new Action(_ => + using (combined.Token.Register(() => tcs.TrySetCanceled())) { - tcs.TrySetResult(vars.Data!); - })); + var context = + CreateEngine(options) + .Extend(vars, options) + .Extend(extensions) + .ExtendAsync(extensions, tcs.TrySetException, combined.Token); - context.Engine.SetValue("replace", new Action(() => - { - var dataInstance = context.Engine.GetValue("ctx").AsObject().Get("data"); + context.Engine.SetValue("complete", new Action(_ => + { + tcs.TrySetResult(vars.Data!); + })); - if (dataInstance != null && dataInstance.IsObject() && dataInstance.AsObject() is ContentDataObject data) + context.Engine.SetValue("replace", new Action(() => { - if (!tcs.Task.IsCompleted) + var dataInstance = context.Engine.GetValue("ctx").AsObject().Get("data"); + + if (dataInstance != null && dataInstance.IsObject() && dataInstance.AsObject() is ContentDataObject data) { - if (data.TryUpdate(out var modified)) + if (!tcs.Task.IsCompleted) { - tcs.TrySetResult(modified); - } - else - { - tcs.TrySetResult(vars.Data!); + if (data.TryUpdate(out var modified)) + { + tcs.TrySetResult(modified); + } + else + { + tcs.TrySetResult(vars.Data!); + } } } - } - })); + })); - Execute(context.Engine, script); + Execute(context.Engine, script); - if (!context.IsAsync) - { - tcs.TrySetResult(vars.Data!); - } + if (!context.IsAsync) + { + tcs.TrySetResult(vars.Data!); + } - return await tcs.Task; + return await tcs.Task; + } } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository.cs index 44fc8513b..aad1d91a3 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository.cs @@ -30,7 +30,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets return "States_AssetFolders2"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct = default) { return collection.Indexes.CreateManyAsync(new[] { @@ -42,7 +43,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets }, ct); } - public async Task> QueryAsync(DomainId appId, DomainId parentId) + public async Task> QueryAsync(DomainId appId, DomainId parentId, + CancellationToken ct = default) { using (Profiler.TraceMethod("QueryAsyncByQuery")) { @@ -50,13 +52,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets var assetFolderEntities = await Collection.Find(filter).SortBy(x => x.FolderName) - .ToListAsync(); + .ToListAsync(ct = default); return ResultList.Create(assetFolderEntities.Count, assetFolderEntities); } } - public async Task> QueryChildIdsAsync(DomainId appId, DomainId parentId) + public async Task> QueryChildIdsAsync(DomainId appId, DomainId parentId, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { @@ -64,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets var assetFolderEntities = await Collection.Find(filter).Only(x => x.Id) - .ToListAsync(); + .ToListAsync(ct = default); var field = Field.Of(x => nameof(x.Id)); @@ -72,7 +75,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - public async Task FindAssetFolderAsync(DomainId appId, DomainId id) + public async Task FindAssetFolderAsync(DomainId appId, DomainId id, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { @@ -80,7 +84,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets var assetFolderEntity = await Collection.Find(x => x.DocumentId == documentId && !x.IsDeleted) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(ct = default); return assetFolderEntity; } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository_SnapshotStore.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository_SnapshotStore.cs index 0f7ce8d9d..c89f00daf 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository_SnapshotStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetFolderRepository_SnapshotStore.cs @@ -65,11 +65,12 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - async Task ISnapshotStore.ReadAllAsync(Func callback, CancellationToken ct) + async Task ISnapshotStore.ReadAllAsync(Func callback, + CancellationToken ct) { using (Profiler.TraceMethod()) { - await Collection.Find(new BsonDocument(), options: Batching.Options).ForEachPipedAsync(x => callback(Map(x), x.Version), ct); + await Collection.Find(new BsonDocument(), Batching.Options).ForEachPipedAsync(x => callback(Map(x), x.Version), ct); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs index f1086ad30..6404fc183 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -39,7 +39,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets return "States_Assets2"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct = default) { return collection.Indexes.CreateManyAsync(new[] { @@ -74,9 +75,9 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets { var find = Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted); - using (var cursor = await find.ToCursorAsync(ct)) + using (var cursor = await find.ToCursorAsync(ct = default)) { - while (await cursor.MoveNextAsync(ct)) + while (await cursor.MoveNextAsync(ct = default)) { foreach (var entity in cursor.Current) { @@ -86,7 +87,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - public async Task> QueryAsync(DomainId appId, DomainId? parentId, Q q) + public async Task> QueryAsync(DomainId appId, DomainId? parentId, Q q, + CancellationToken ct = default) { using (Profiler.TraceMethod("QueryAsyncByQuery")) { @@ -100,7 +102,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets await Collection.Find(filter).SortByDescending(x => x.LastModified) .QueryLimit(q.Query) .QuerySkip(q.Query) - .ToListAsync(); + .ToListAsync(ct = default); long assetTotal = assetEntities.Count; if (q.NoTotal) @@ -109,7 +111,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } else if (assetEntities.Count >= q.Query.Take || q.Query.Skip > 0) { - assetTotal = await Collection.Find(filter).CountDocumentsAsync(); + assetTotal = await Collection.Find(filter).CountDocumentsAsync(ct = default); } return ResultList.Create(assetTotal, assetEntities.OfType()); @@ -125,7 +127,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets .QueryLimit(query) .QuerySkip(query) .QuerySort(query) - .ToListAsync(); + .ToListAsync(ct = default); long assetTotal = assetEntities.Count; if (q.NoTotal) @@ -134,7 +136,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } else if (assetEntities.Count >= q.Query.Take || q.Query.Skip > 0) { - assetTotal = await Collection.Find(filter).CountDocumentsAsync(); + assetTotal = await Collection.Find(filter).CountDocumentsAsync(ct = default); } return ResultList.Create(assetTotal, assetEntities); @@ -147,13 +149,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - public async Task> QueryIdsAsync(DomainId appId, HashSet ids) + public async Task> QueryIdsAsync(DomainId appId, HashSet ids, + CancellationToken ct = default) { using (Profiler.TraceMethod("QueryAsyncByIds")) { var assetEntities = await Collection.Find(BuildFilter(appId, ids)).Only(x => x.Id) - .ToListAsync(); + .ToListAsync(ct = default); var field = Field.Of(x => nameof(x.Id)); @@ -161,13 +164,14 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - public async Task> QueryChildIdsAsync(DomainId appId, DomainId parentId) + public async Task> QueryChildIdsAsync(DomainId appId, DomainId parentId, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { var assetEntities = await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.ParentId == parentId).Only(x => x.Id) - .ToListAsync(); + .ToListAsync(ct = default); var field = Field.Of(x => nameof(x.Id)); @@ -175,31 +179,34 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - public async Task FindAssetByHashAsync(DomainId appId, string hash, string fileName, long fileSize) + public async Task FindAssetByHashAsync(DomainId appId, string hash, string fileName, long fileSize, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { var assetEntity = await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.FileHash == hash && x.FileName == fileName && x.FileSize == fileSize) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(ct = default); return assetEntity; } } - public async Task FindAssetBySlugAsync(DomainId appId, string slug) + public async Task FindAssetBySlugAsync(DomainId appId, string slug, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { var assetEntity = await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.Slug == slug) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(ct = default); return assetEntity; } } - public async Task FindAssetAsync(DomainId appId, DomainId id) + public async Task FindAssetAsync(DomainId appId, DomainId id, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { @@ -207,19 +214,20 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets var assetEntity = await Collection.Find(x => x.DocumentId == documentId && !x.IsDeleted) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(ct = default); return assetEntity; } } - public async Task FindAssetAsync(DomainId id) + public async Task FindAssetAsync(DomainId id, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { var assetEntity = await Collection.Find(x => x.Id == id && !x.IsDeleted) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(ct = default); return assetEntity; } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository_SnapshotStore.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository_SnapshotStore.cs index 5b37cd1bf..3722f2ae0 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository_SnapshotStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository_SnapshotStore.cs @@ -65,11 +65,12 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets } } - async Task ISnapshotStore.ReadAllAsync(Func callback, CancellationToken ct) + async Task ISnapshotStore.ReadAllAsync(Func callback, + CancellationToken ct) { using (Profiler.TraceMethod()) { - await Collection.Find(new BsonDocument(), options: Batching.Options).ForEachPipedAsync(x => callback(Map(x), x.Version), ct); + await Collection.Find(new BsonDocument(), Batching.Options).ForEachPipedAsync(x => callback(Map(x), x.Version), ct); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs index dbbbcf721..471295b03 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentCollection.cs @@ -61,7 +61,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents return name; } - protected override async Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override async Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { if (useWildcardIndex) { @@ -82,89 +83,103 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents await queryScheduled.PrepareAsync(collection, skipIndex, ct); } - public IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds, CancellationToken ct) + public Task ResetScheduledAsync(DomainId documentId, + CancellationToken ct) + { + return Collection.UpdateOneAsync(x => x.DocumentId == documentId, Update.Unset(x => x.ScheduleJob).Unset(x => x.ScheduledAt), cancellationToken: ct); + } + + public IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds, + CancellationToken ct) { return queryAsStream.StreamAll(appId, schemaIds, ct); } - public async Task> QueryAsync(IAppEntity app, List schemas, Q q) + public async Task> QueryAsync(IAppEntity app, List schemas, Q q, + CancellationToken ct) { using (Profiler.TraceMethod()) { if (q.Ids != null && q.Ids.Count > 0) { - return await queryByIds.QueryAsync(app.Id, schemas, q); + return await queryByIds.QueryAsync(app.Id, schemas, q, ct); } if (q.Referencing != default) { - return await queryReferences.QueryAsync(app.Id, schemas, q); + return await queryReferences.QueryAsync(app.Id, schemas, q, ct); } if (q.Reference != default) { - return await queryByQuery.QueryAsync(app, schemas, q); + return await queryByQuery.QueryAsync(app, schemas, q, ct); } return ResultList.CreateFrom(0); } } - public async Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q) + public async Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, + CancellationToken ct) { using (Profiler.TraceMethod()) { if (q.Ids != null && q.Ids.Count > 0) { - return await queryByIds.QueryAsync(app.Id, new List { schema }, q); + return await queryByIds.QueryAsync(app.Id, new List { schema }, q, ct); } if (q.Referencing == default) { - return await queryByQuery.QueryAsync(app, schema, q); + return await queryByQuery.QueryAsync(app, schema, q, ct); } return ResultList.CreateFrom(0); } } - public async Task FindContentAsync(ISchemaEntity schema, DomainId id) + public async Task FindContentAsync(ISchemaEntity schema, DomainId id, + CancellationToken ct) { using (Profiler.TraceMethod()) { - return await queryBdId.QueryAsync(schema, id); + return await queryBdId.QueryAsync(schema, id, ct); } } - public async Task QueryScheduledWithoutDataAsync(Instant now, Func callback) + public async Task QueryScheduledWithoutDataAsync(Instant now, Func callback, + CancellationToken ct) { using (Profiler.TraceMethod()) { - await queryScheduled.QueryAsync(now, callback); + await queryScheduled.QueryAsync(now, callback, ct); } } - public async Task> QueryIdsAsync(DomainId appId, HashSet ids) + public async Task> QueryIdsAsync(DomainId appId, HashSet ids, + CancellationToken ct) { using (Profiler.TraceMethod()) { - return await queryByIds.QueryIdsAsync(appId, ids); + return await queryByIds.QueryIdsAsync(appId, ids, ct); } } - public async Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode) + public async Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode, + CancellationToken ct) { using (Profiler.TraceMethod()) { - return await queryByQuery.QueryIdsAsync(appId, schemaId, filterNode); + return await queryByQuery.QueryIdsAsync(appId, schemaId, filterNode, ct); } } - public async Task HasReferrersAsync(DomainId appId, DomainId contentId) + public async Task HasReferrersAsync(DomainId appId, DomainId contentId, + CancellationToken ct) { using (Profiler.TraceMethod()) { - return await queryReferrers.CheckExistsAsync(appId, contentId); + return await queryReferrers.CheckExistsAsync(appId, contentId, ct); } } @@ -175,11 +190,6 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents return result?["vs"].AsInt64 ?? EtagVersion.Empty; } - public Task ResetScheduledAsync(DomainId documentId) - { - return Collection.UpdateOneAsync(x => x.DocumentId == documentId, Update.Unset(x => x.ScheduleJob).Unset(x => x.ScheduledAt)); - } - public Task UpsertVersionedAsync(DomainId documentId, long oldVersion, MongoContentEntity entity) { return Collection.UpsertVersionedAsync(documentId, oldVersion, entity.Version, entity); diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs index c863a1568..fd4236e36 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs @@ -55,84 +55,93 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents await collectionPublished.InitializeAsync(ct); } - public IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds, CancellationToken ct) + public IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds, + CancellationToken ct = default) { return collectionAll.StreamAll(appId, schemaIds, ct); } - public Task> QueryAsync(IAppEntity app, List schemas, Q q, SearchScope scope) + public Task> QueryAsync(IAppEntity app, List schemas, Q q, SearchScope scope, + CancellationToken ct = default) { if (scope == SearchScope.All) { - return collectionAll.QueryAsync(app, schemas, q); + return collectionAll.QueryAsync(app, schemas, q, ct); } else { - return collectionPublished.QueryAsync(app, schemas, q); + return collectionPublished.QueryAsync(app, schemas, q, ct); } } - public Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, SearchScope scope) + public Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, SearchScope scope, + CancellationToken ct = default) { if (scope == SearchScope.All) { - return collectionAll.QueryAsync(app, schema, q); + return collectionAll.QueryAsync(app, schema, q, ct); } else { - return collectionPublished.QueryAsync(app, schema, q); + return collectionPublished.QueryAsync(app, schema, q, ct); } } - public Task FindContentAsync(IAppEntity app, ISchemaEntity schema, DomainId id, SearchScope scope) + public Task FindContentAsync(IAppEntity app, ISchemaEntity schema, DomainId id, SearchScope scope, + CancellationToken ct = default) { if (scope == SearchScope.All) { - return collectionAll.FindContentAsync(schema, id); + return collectionAll.FindContentAsync(schema, id, ct); } else { - return collectionPublished.FindContentAsync(schema, id); + return collectionPublished.FindContentAsync(schema, id, ct); } } - public Task> QueryIdsAsync(DomainId appId, HashSet ids, SearchScope scope) + public Task> QueryIdsAsync(DomainId appId, HashSet ids, SearchScope scope, + CancellationToken ct = default) { if (scope == SearchScope.All) { - return collectionAll.QueryIdsAsync(appId, ids); + return collectionAll.QueryIdsAsync(appId, ids, ct); } else { - return collectionPublished.QueryIdsAsync(appId, ids); + return collectionPublished.QueryIdsAsync(appId, ids, ct); } } - public Task HasReferrersAsync(DomainId appId, DomainId contentId, SearchScope scope) + public Task HasReferrersAsync(DomainId appId, DomainId contentId, SearchScope scope, + CancellationToken ct = default) { if (scope == SearchScope.All) { - return collectionAll.HasReferrersAsync(appId, contentId); + return collectionAll.HasReferrersAsync(appId, contentId, ct); } else { - return collectionPublished.HasReferrersAsync(appId, contentId); + return collectionPublished.HasReferrersAsync(appId, contentId, ct); } } - public Task ResetScheduledAsync(DomainId documentId) + public Task ResetScheduledAsync(DomainId documentId, + CancellationToken ct = default) { - return collectionAll.ResetScheduledAsync(documentId); + return collectionAll.ResetScheduledAsync(documentId, ct); } - public Task QueryScheduledWithoutDataAsync(Instant now, Func callback) + public Task QueryScheduledWithoutDataAsync(Instant now, Func callback, + CancellationToken ct = default) { - return collectionAll.QueryScheduledWithoutDataAsync(now, callback); + return collectionAll.QueryScheduledWithoutDataAsync(now, callback, ct); } - public Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode) + public Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode, + CancellationToken ct = default) { - return collectionAll.QueryIdsAsync(appId, schemaId, filterNode); + return collectionAll.QueryIdsAsync(appId, schemaId, filterNode, ct); } public IEnumerable> GetInternalCollections() diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs index ae32db06a..49d071264 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs @@ -21,7 +21,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents { public partial class MongoContentRepository : ISnapshotStore { - Task ISnapshotStore.ReadAllAsync(Func callback, CancellationToken ct) + Task ISnapshotStore.ReadAllAsync(Func callback, + CancellationToken ct) { return Task.CompletedTask; } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs index 91b8aaf9d..f48293e7b 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/Extensions.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; @@ -35,7 +36,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations public Status Status { get; set; } } - public static Task> FindStatusAsync(this IMongoCollection collection, FilterDefinition filter) + public static Task> FindStatusAsync(this IMongoCollection collection, FilterDefinition filter, + CancellationToken ct) { var projections = Builders.Projection; @@ -44,7 +46,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations .Include(x => x.Id) .Include(x => x.IndexedSchemaId) .Include(x => x.Status)) - .ToListAsync(); + .ToListAsync(ct); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/OperationBase.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/OperationBase.cs index aa063929d..6f9facfc1 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/OperationBase.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/OperationBase.cs @@ -31,7 +31,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } } - protected virtual Task PrepareAsync(CancellationToken ct = default) + protected virtual Task PrepareAsync(CancellationToken ct) { return Task.CompletedTask; } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryAsStream.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryAsStream.cs index 3bfb779e4..f2bf88040 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryAsStream.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryAsStream.cs @@ -17,7 +17,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations { public sealed class QueryAsStream : OperationBase { - protected override async Task PrepareAsync(CancellationToken ct = default) + protected override async Task PrepareAsync(CancellationToken ct) { var indexBySchema = new CreateIndexModel(Index diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryById.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryById.cs index d60afce3f..0a9be2ce4 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryById.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryById.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using Squidex.Domain.Apps.Entities.Contents; @@ -15,7 +16,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations { internal sealed class QueryById : OperationBase { - public async Task QueryAsync(ISchemaEntity schema, DomainId id) + public async Task QueryAsync(ISchemaEntity schema, DomainId id, + CancellationToken ct) { Guard.NotNull(schema, nameof(schema)); @@ -23,7 +25,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations var find = Collection.Find(x => x.DocumentId == documentId); - var contentEntity = await find.FirstOrDefaultAsync(); + var contentEntity = await find.FirstOrDefaultAsync(ct); if (contentEntity != null) { diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByIds.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByIds.cs index c27328c03..273ba234d 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByIds.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByIds.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using Squidex.Domain.Apps.Core.Contents; @@ -20,7 +21,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations { internal sealed class QueryByIds : OperationBase { - public async Task> QueryIdsAsync(DomainId appId, HashSet ids) + public async Task> QueryIdsAsync(DomainId appId, HashSet ids, + CancellationToken ct) { if (ids == null || ids.Count == 0) { @@ -29,12 +31,13 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations var filter = CreateFilter(appId, null, ids); - var contentItems = await Collection.FindStatusAsync(filter); + var contentItems = await Collection.FindStatusAsync(filter, ct); return contentItems.Select(x => (x.IndexedSchemaId, x.Id, x.Status)).ToList(); } - public async Task> QueryAsync(DomainId appId, List schemas, Q q) + public async Task> QueryAsync(DomainId appId, List schemas, Q q, + CancellationToken ct) { Guard.NotNull(q, nameof(q)); @@ -54,7 +57,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } else if (contentTotal >= q.Query.Take || q.Query.Skip > 0) { - contentTotal = await Collection.Find(filter).CountDocumentsAsync(); + contentTotal = await Collection.Find(filter).CountDocumentsAsync(ct); } return ResultList.Create(contentTotal, contentEntities); diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByQuery.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByQuery.cs index 1a6a082e0..7ef366378 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByQuery.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryByQuery.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -41,7 +41,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations this.appProvider = appProvider; } - protected override async Task PrepareAsync(CancellationToken ct = default) + protected override async Task PrepareAsync(CancellationToken ct) { var indexBySchemaWithRefs = new CreateIndexModel(Index @@ -62,7 +62,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations await Collection.Indexes.CreateOneAsync(indexBySchema, cancellationToken: ct); } - public async Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode) + public async Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode, + CancellationToken ct) { Guard.NotNull(filterNode, nameof(filterNode)); @@ -77,7 +78,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations var filter = BuildFilter(appId, schemaId, filterNode.AdjustToModel(appId)); - var contentItems = await Collection.FindStatusAsync(filter); + var contentItems = await Collection.FindStatusAsync(filter, ct); return contentItems.Select(x => (x.IndexedSchemaId, x.Id, x.Status)).ToList(); } @@ -91,7 +92,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } } - public async Task> QueryAsync(IAppEntity app, List schemas, Q q) + public async Task> QueryAsync(IAppEntity app, List schemas, Q q, + CancellationToken ct) { Guard.NotNull(app, nameof(app)); Guard.NotNull(q, nameof(q)); @@ -102,7 +104,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations var filter = CreateFilter(app.Id, schemas.Select(x => x.Id), query, q.Reference, q.CreatedBy); - var contentEntities = await FindContentsAsync(query, filter); + var contentEntities = await FindContentsAsync(query, filter, ct); var contentTotal = (long)contentEntities.Count; if (q.NoTotal) @@ -111,7 +113,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } else if (contentTotal >= q.Query.Take || q.Query.Skip > 0) { - contentTotal = await Collection.Find(filter).CountDocumentsAsync(); + contentTotal = await Collection.Find(filter).CountDocumentsAsync(ct); } return ResultList.Create(contentTotal, contentEntities); @@ -126,7 +128,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } } - public async Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q) + public async Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, + CancellationToken ct) { Guard.NotNull(app, nameof(app)); Guard.NotNull(schema, nameof(schema)); @@ -138,7 +141,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations var filter = CreateFilter(schema.AppId.Id, Enumerable.Repeat(schema.Id, 1), query, q.Reference, q.CreatedBy); - var contentEntities = await FindContentsAsync(query, filter); + var contentEntities = await FindContentsAsync(query, filter, ct); var contentTotal = (long)contentEntities.Count; if (q.NoTotal) @@ -147,7 +150,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } else if (contentTotal >= q.Query.Take || q.Query.Skip > 0) { - contentTotal = await Collection.Find(filter).CountDocumentsAsync(); + contentTotal = await Collection.Find(filter).CountDocumentsAsync(ct); } return ResultList.Create(contentTotal, contentEntities); @@ -162,7 +165,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations } } - private async Task> FindContentsAsync(ClrQuery query, FilterDefinition filter) + private async Task> FindContentsAsync(ClrQuery query, FilterDefinition filter, + CancellationToken ct) { if (query.Skip > 0 && !IsSatisfiedByIndex(query)) { @@ -181,7 +185,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations .QuerySkip(query) .QueryLimit(query) .Lookup(Collection, x => x.Id, x => x.DocumentId, x => x.Joined) - .ToListAsync(); + .ToListAsync(ct); return joined.Select(x => x.Joined[0]).ToList(); } @@ -191,7 +195,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations .QuerySort(query) .QueryLimit(query) .QuerySkip(query) - .ToListAsync(); + .ToListAsync(ct); return await result; } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs index 177c59503..4cb04cfb7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferences.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using MongoDB.Bson.Serialization.Attributes; using MongoDB.Driver; @@ -36,7 +37,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations this.queryByIds = queryByIds; } - public async Task> QueryAsync(DomainId appId, List schemas, Q q) + public async Task> QueryAsync(DomainId appId, List schemas, Q q, + CancellationToken ct) { var documentId = DomainId.Combine(appId, q.Referencing); @@ -45,7 +47,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations .Find(x => x.DocumentId == documentId) .Project(Projection.Include(x => x.ReferencedIds)); - var contentEntity = await find.FirstOrDefaultAsync(); + var contentEntity = await find.FirstOrDefaultAsync(ct); if (contentEntity == null) { @@ -59,7 +61,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations q = q.WithReferencing(default).WithIds(contentEntity.ReferencedIds!); - return await queryByIds.QueryAsync(appId, schemas, q); + return await queryByIds.QueryAsync(appId, schemas, q, ct); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferrers.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferrers.cs index 5770f17b5..9d2e519c6 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferrers.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryReferrers.cs @@ -15,7 +15,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations { internal sealed class QueryReferrers : OperationBase { - protected override Task PrepareAsync(CancellationToken ct = default) + protected override Task PrepareAsync(CancellationToken ct) { var index = new CreateIndexModel(Index @@ -26,7 +26,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations return Collection.Indexes.CreateOneAsync(index, cancellationToken: ct); } - public async Task CheckExistsAsync(DomainId appId, DomainId contentId) + public async Task CheckExistsAsync(DomainId appId, DomainId contentId, + CancellationToken ct) { var filter = Filter.And( @@ -37,9 +38,9 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations var hasReferrerAsync = await Collection.Find(filter).Only(x => x.Id) - .AnyAsync(); + .AnyAsync(ct); return hasReferrerAsync; } } -} \ No newline at end of file +} diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryScheduled.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryScheduled.cs index 46c6d3c97..5970040b6 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryScheduled.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Contents/Operations/QueryScheduled.cs @@ -18,7 +18,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations { internal sealed class QueryScheduled : OperationBase { - protected override Task PrepareAsync(CancellationToken ct = default) + protected override Task PrepareAsync(CancellationToken ct) { var index = new CreateIndexModel(Index @@ -28,7 +28,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations return Collection.Indexes.CreateOneAsync(index, cancellationToken: ct); } - public Task QueryAsync(Instant now, Func callback) + public Task QueryAsync(Instant now, Func callback, + CancellationToken ct) { Guard.NotNull(callback, nameof(callback)); @@ -36,7 +37,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents.Operations .ForEachAsync(c => { callback(c); - }); + }, ct); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/FullText/MongoTextIndex.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/FullText/MongoTextIndex.cs index 24a675609..eb975f0cb 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/FullText/MongoTextIndex.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/FullText/MongoTextIndex.cs @@ -30,7 +30,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.FullText { } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { return collection.Indexes.CreateManyAsync(new[] { diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs index aedddbb7d..f861e946e 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/History/MongoHistoryEventRepository.cs @@ -41,7 +41,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.History return "Projections_History"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct = default) { return collection.Indexes.CreateManyAsync(new[] { diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs index 48aa3f248..bb75dc070 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleEventRepository.cs @@ -36,9 +36,10 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules return "RuleEvents"; } - protected override async Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override async Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct = default) { - await statisticsCollection.InitializeAsync(ct); + await statisticsCollection.InitializeAsync(ct = default); await collection.Indexes.CreateManyAsync(new[] { @@ -63,7 +64,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules return Collection.Find(x => x.NextAttempt < now).ForEachAsync(callback, ct); } - public async Task> QueryByAppAsync(DomainId appId, DomainId? ruleId = null, int skip = 0, int take = 20) + public async Task> QueryByAppAsync(DomainId appId, DomainId? ruleId = null, int skip = 0, int take = 20, CancellationToken ct = default) { var filter = Filter.Eq(x => x.AppId, appId); @@ -72,22 +73,22 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules filter = Filter.And(filter, Filter.Eq(x => x.RuleId, ruleId.Value)); } - var ruleEventEntities = await Collection.Find(filter).Skip(skip).Limit(take).SortByDescending(x => x.Created).ToListAsync(); + var ruleEventEntities = await Collection.Find(filter).Skip(skip).Limit(take).SortByDescending(x => x.Created).ToListAsync(ct = default); var ruleEventTotal = (long)ruleEventEntities.Count; if (ruleEventTotal >= take || skip > 0) { - ruleEventTotal = await Collection.Find(filter).CountDocumentsAsync(); + ruleEventTotal = await Collection.Find(filter).CountDocumentsAsync(ct = default); } return ResultList.Create(ruleEventTotal, ruleEventEntities); } - public async Task FindAsync(DomainId id) + public async Task FindAsync(DomainId id, CancellationToken ct = default) { var ruleEvent = await Collection.Find(x => x.DocumentId == id) - .FirstOrDefaultAsync(); + .FirstOrDefaultAsync(ct = default); return ruleEvent; } @@ -149,9 +150,9 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules } } - public Task> QueryStatisticsByAppAsync(DomainId appId) + public Task> QueryStatisticsByAppAsync(DomainId appId, CancellationToken ct = default) { - return statisticsCollection.QueryByAppAsync(appId); + return statisticsCollection.QueryByAppAsync(appId, ct); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleStatisticsCollection.cs b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleStatisticsCollection.cs index 091d6c18a..6ee7d76e9 100644 --- a/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleStatisticsCollection.cs +++ b/backend/src/Squidex.Domain.Apps.Entities.MongoDb/Rules/MongoRuleStatisticsCollection.cs @@ -39,7 +39,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules return "RuleStatistics"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { return collection.Indexes.CreateOneAsync( new CreateIndexModel( @@ -49,9 +50,10 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Rules cancellationToken: ct); } - public async Task> QueryByAppAsync(DomainId appId) + public async Task> QueryByAppAsync(DomainId appId, + CancellationToken ct) { - var statistics = await Collection.Find(x => x.AppId == appId).ToListAsync(); + var statistics = await Collection.Find(x => x.AppId == appId).ToListAsync(ct); return statistics; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppSettingsSearchSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppSettingsSearchSource.cs index 9ed3dee7a..17138f2f7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/AppSettingsSearchSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/AppSettingsSearchSource.cs @@ -6,6 +6,7 @@ // ========================================================================== using System; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Entities.Search; @@ -26,7 +27,8 @@ namespace Squidex.Domain.Apps.Entities.Apps this.urlGenerator = urlGenerator; } - public Task SearchAsync(string query, Context context) + public Task SearchAsync(string query, Context context, + CancellationToken ct) { var result = new SearchResults(); @@ -81,4 +83,4 @@ namespace Squidex.Domain.Apps.Entities.Apps return Task.FromResult(result); } } -} \ No newline at end of file +} diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppImageStore.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppImageStore.cs index f0e616d9e..94b4be2da 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppImageStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppImageStore.cs @@ -24,14 +24,16 @@ namespace Squidex.Domain.Apps.Entities.Apps this.assetStore = assetStore; } - public Task DownloadAsync(DomainId appId, Stream stream, CancellationToken ct = default) + public Task DownloadAsync(DomainId appId, Stream stream, + CancellationToken ct = default) { var fileName = GetFileName(appId); return assetStore.DownloadAsync(fileName, stream, default, ct); } - public Task UploadAsync(DomainId appId, Stream stream, CancellationToken ct = default) + public Task UploadAsync(DomainId appId, Stream stream, + CancellationToken ct = default) { var fileName = GetFileName(appId); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppLogStore.cs b/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppLogStore.cs index 655c9cf30..3ce41bc53 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppLogStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Apps/DefaultAppLogStore.cs @@ -74,7 +74,8 @@ namespace Squidex.Domain.Apps.Entities.Apps return requestLogStore.LogAsync(storedRequest); } - public async Task ReadLogAsync(DomainId appId, DateTime fromDate, DateTime toDate, Stream stream, CancellationToken ct = default) + public async Task ReadLogAsync(DomainId appId, DateTime fromDate, DateTime toDate, Stream stream, + CancellationToken ct = default) { Guard.NotNull(appId, nameof(appId)); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsSearchSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsSearchSource.cs index e998cff68..3b1dcceb2 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsSearchSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/AssetsSearchSource.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Entities.Apps; @@ -30,7 +31,8 @@ namespace Squidex.Domain.Apps.Entities.Assets this.urlGenerator = urlGenerator; } - public async Task SearchAsync(string query, Context context) + public async Task SearchAsync(string query, Context context, + CancellationToken ct) { var result = new SearchResults(); @@ -40,7 +42,7 @@ namespace Squidex.Domain.Apps.Entities.Assets var clrQuery = new ClrQuery { Filter = filter, Take = 5 }; - var assets = await assetQuery.QueryAsync(context, null, Q.Empty.WithQuery(clrQuery)); + var assets = await assetQuery.QueryAsync(context, null, Q.Empty.WithQuery(clrQuery), ct); if (assets.Count > 0) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/DefaultAssetFileStore.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/DefaultAssetFileStore.cs index 5074d6138..1aa7a0010 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/DefaultAssetFileStore.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/DefaultAssetFileStore.cs @@ -29,7 +29,8 @@ namespace Squidex.Domain.Apps.Entities.Assets return assetStore.GeneratePublicUrl(fileName); } - public async Task GetFileSizeAsync(DomainId appId, DomainId id, long fileVersion, CancellationToken ct = default) + public async Task GetFileSizeAsync(DomainId appId, DomainId id, long fileVersion, + CancellationToken ct = default) { try { @@ -45,7 +46,8 @@ namespace Squidex.Domain.Apps.Entities.Assets } } - public async Task DownloadAsync(DomainId appId, DomainId id, long fileVersion, Stream stream, BytesRange range = default, CancellationToken ct = default) + public async Task DownloadAsync(DomainId appId, DomainId id, long fileVersion, Stream stream, BytesRange range = default, + CancellationToken ct = default) { try { @@ -61,19 +63,22 @@ namespace Squidex.Domain.Apps.Entities.Assets } } - public Task UploadAsync(DomainId appId, DomainId id, long fileVersion, Stream stream, CancellationToken ct = default) + public Task UploadAsync(DomainId appId, DomainId id, long fileVersion, Stream stream, + CancellationToken ct = default) { var fileName = GetFileName(appId, id, fileVersion); return assetStore.UploadAsync(fileName, stream, true, ct); } - public Task UploadAsync(string tempFile, Stream stream, CancellationToken ct = default) + public Task UploadAsync(string tempFile, Stream stream, + CancellationToken ct = default) { return assetStore.UploadAsync(tempFile, stream, false, ct); } - public Task CopyAsync(string tempFile, DomainId appId, DomainId id, long fileVersion, CancellationToken ct = default) + public Task CopyAsync(string tempFile, DomainId appId, DomainId id, long fileVersion, + CancellationToken ct = default) { var fileName = GetFileName(appId, id, fileVersion); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetCommandMiddleware.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetCommandMiddleware.cs index b5e5cf259..295488564 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetCommandMiddleware.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/AssetCommandMiddleware.cs @@ -158,7 +158,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject if (payload is not IEnrichedAssetEntity) { - payload = await assetEnricher.EnrichAsync(asset, contextProvider.Context); + payload = await assetEnricher.EnrichAsync(asset, contextProvider.Context, default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/Guards/GuardAsset.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/Guards/GuardAsset.cs index 442718e34..02212ab41 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/Guards/GuardAsset.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/DomainObject/Guards/GuardAsset.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -43,7 +43,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards if (command.CheckReferrers) { - var hasReferrer = await contentRepository.HasReferrersAsync(asset.AppId.Id, asset.Id, SearchScope.All); + var hasReferrer = await contentRepository.HasReferrersAsync(asset.AppId.Id, asset.Id, SearchScope.All, default); if (hasReferrer) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetEnricher.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetEnricher.cs index bbe599cca..2b2bf18cc 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetEnricher.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetEnricher.cs @@ -6,14 +6,15 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace Squidex.Domain.Apps.Entities.Assets { public interface IAssetEnricher { - Task EnrichAsync(IAssetEntity asset, Context context); + Task EnrichAsync(IAssetEntity asset, Context context, CancellationToken ct = default); - Task> EnrichAsync(IEnumerable assets, Context context); + Task> EnrichAsync(IEnumerable assets, Context context, CancellationToken ct = default); } -} \ No newline at end of file +} diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetQueryService.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetQueryService.cs index 0510fa4e8..07dcc4423 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetQueryService.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/IAssetQueryService.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Squidex.Infrastructure; @@ -13,20 +14,20 @@ namespace Squidex.Domain.Apps.Entities.Assets { public interface IAssetQueryService { - Task> QueryAsync(Context context, DomainId? parentId, Q q); + Task> QueryAsync(Context context, DomainId? parentId, Q q, CancellationToken ct = default); - Task> QueryAssetFoldersAsync(Context context, DomainId parentId); + Task> QueryAssetFoldersAsync(Context context, DomainId parentId, CancellationToken ct = default); - Task> QueryAssetFoldersAsync(DomainId appId, DomainId parentId); + Task> QueryAssetFoldersAsync(DomainId appId, DomainId parentId, CancellationToken ct = default); - Task> FindAssetFolderAsync(DomainId appId, DomainId id); + Task> FindAssetFolderAsync(DomainId appId, DomainId id, CancellationToken ct = default); - Task FindByHashAsync(Context context, string hash, string fileName, long fileSize); + Task FindByHashAsync(Context context, string hash, string fileName, long fileSize, CancellationToken ct = default); - Task FindAsync(Context context, DomainId id, long version = EtagVersion.Any); + Task FindAsync(Context context, DomainId id, long version = EtagVersion.Any, CancellationToken ct = default); - Task FindBySlugAsync(Context context, string slug); + Task FindBySlugAsync(Context context, string slug, CancellationToken ct = default); - Task FindGlobalAsync(Context context, DomainId id); + Task FindGlobalAsync(Context context, DomainId id, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetEnricher.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetEnricher.cs index 1a1a64e2b..e5d0c11d4 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetEnricher.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetEnricher.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Tags; using Squidex.Infrastructure; @@ -34,17 +35,19 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries this.requestCache = requestCache; } - public async Task EnrichAsync(IAssetEntity asset, Context context) + public async Task EnrichAsync(IAssetEntity asset, Context context, + CancellationToken ct) { Guard.NotNull(asset, nameof(asset)); Guard.NotNull(context, nameof(context)); - var enriched = await EnrichAsync(Enumerable.Repeat(asset, 1), context); + var enriched = await EnrichAsync(Enumerable.Repeat(asset, 1), context, ct); return enriched[0]; } - public async Task> EnrichAsync(IEnumerable assets, Context context) + public async Task> EnrichAsync(IEnumerable assets, Context context, + CancellationToken ct) { Guard.NotNull(assets, nameof(assets)); Guard.NotNull(context, nameof(context)); @@ -60,7 +63,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries if (!context.ShouldSkipAssetEnrichment()) { - await EnrichTagsAsync(results); + await EnrichTagsAsync(results, ct); EnrichWithMetadataText(results); } @@ -104,10 +107,13 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries } } - private async Task EnrichTagsAsync(List assets) + private async Task EnrichTagsAsync(List assets, + CancellationToken ct) { foreach (var group in assets.GroupBy(x => x.AppId.Id)) { + ct.ThrowIfCancellationRequested(); + var tagsById = await CalculateTags(group); foreach (var asset in group) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryService.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryService.cs index ff6faa252..e82d7ece2 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryService.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/Queries/AssetQueryService.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Assets.Repositories; using Squidex.Infrastructure; @@ -43,7 +44,8 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries this.queryParser = queryParser; } - public async Task> FindAssetFolderAsync(DomainId appId, DomainId id) + public async Task> FindAssetFolderAsync(DomainId appId, DomainId id, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { @@ -51,7 +53,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries while (id != DomainId.Empty) { - var folder = await assetFolderRepository.FindAssetFolderAsync(appId, id); + var folder = await assetFolderRepository.FindAssetFolderAsync(appId, id, ct); if (folder == null || result.Any(x => x.Id == folder.Id)) { @@ -68,78 +70,84 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries } } - public async Task> QueryAssetFoldersAsync(DomainId appId, DomainId parentId) + public async Task> QueryAssetFoldersAsync(DomainId appId, DomainId parentId, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { - var assetFolders = await assetFolderRepository.QueryAsync(appId, parentId); + var assetFolders = await assetFolderRepository.QueryAsync(appId, parentId, ct); return assetFolders; } } - public async Task> QueryAssetFoldersAsync(Context context, DomainId parentId) + public async Task> QueryAssetFoldersAsync(Context context, DomainId parentId, + CancellationToken ct = default) { using (Profiler.TraceMethod()) { - var assetFolders = await assetFolderRepository.QueryAsync(context.App.Id, parentId); + var assetFolders = await assetFolderRepository.QueryAsync(context.App.Id, parentId, ct); return assetFolders; } } - public async Task FindByHashAsync(Context context, string hash, string fileName, long fileSize) + public async Task FindByHashAsync(Context context, string hash, string fileName, long fileSize, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); using (Profiler.TraceMethod()) { - var asset = await assetRepository.FindAssetByHashAsync(context.App.Id, hash, fileName, fileSize); + var asset = await assetRepository.FindAssetByHashAsync(context.App.Id, hash, fileName, fileSize, ct); if (asset == null) { return null; } - return await TransformAsync(context, asset); + return await TransformAsync(context, asset, ct); } } - public async Task FindBySlugAsync(Context context, string slug) + public async Task FindBySlugAsync(Context context, string slug, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); using (Profiler.TraceMethod()) { - var asset = await assetRepository.FindAssetBySlugAsync(context.App.Id, slug); + var asset = await assetRepository.FindAssetBySlugAsync(context.App.Id, slug, ct); if (asset == null) { return null; } - return await TransformAsync(context, asset); + return await TransformAsync(context, asset, ct); } } - public async Task FindGlobalAsync(Context context, DomainId id) + public async Task FindGlobalAsync(Context context, DomainId id, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); using (Profiler.TraceMethod()) { - var asset = await assetRepository.FindAssetAsync(id); + var asset = await assetRepository.FindAssetAsync(id, ct); if (asset == null) { return null; } - return await TransformAsync(context, asset); + return await TransformAsync(context, asset, ct); } } - public async Task FindAsync(Context context, DomainId id, long version = EtagVersion.Any) + public async Task FindAsync(Context context, DomainId id, long version = EtagVersion.Any, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); @@ -153,7 +161,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries } else { - asset = await assetRepository.FindAssetAsync(context.App.Id, id); + asset = await assetRepository.FindAssetAsync(context.App.Id, id, ct); } if (asset == null) @@ -161,11 +169,12 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries return null; } - return await TransformAsync(context, asset); + return await TransformAsync(context, asset, ct); } } - public async Task> QueryAsync(Context context, DomainId? parentId, Q q) + public async Task> QueryAsync(Context context, DomainId? parentId, Q q, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); @@ -178,36 +187,39 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { q = await queryParser.ParseAsync(context, q); - var assets = await assetRepository.QueryAsync(context.App.Id, parentId, q); + var assets = await assetRepository.QueryAsync(context.App.Id, parentId, q, ct); if (q.Ids != null && q.Ids.Count > 0) { assets = assets.SortSet(x => x.Id, q.Ids); } - return await TransformAsync(context, assets); + return await TransformAsync(context, assets, ct); } } - private async Task> TransformAsync(Context context, IResultList assets) + private async Task> TransformAsync(Context context, IResultList assets, + CancellationToken ct) { - var transformed = await TransformCoreAsync(context, assets); + var transformed = await TransformCoreAsync(context, assets, ct); return ResultList.Create(assets.Total, transformed); } - private async Task TransformAsync(Context context, IAssetEntity asset) + private async Task TransformAsync(Context context, IAssetEntity asset, + CancellationToken ct) { - var transformed = await TransformCoreAsync(context, Enumerable.Repeat(asset, 1)); + var transformed = await TransformCoreAsync(context, Enumerable.Repeat(asset, 1), ct); return transformed[0]; } - private async Task> TransformCoreAsync(Context context, IEnumerable assets) + private async Task> TransformCoreAsync(Context context, IEnumerable assets, + CancellationToken ct) { using (Profiler.TraceMethod()) { - return await assetEnricher.EnrichAsync(assets, context); + return await assetEnricher.EnrichAsync(assets, context, ct); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/RebuildFiles.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/RebuildFiles.cs new file mode 100644 index 000000000..26696979f --- /dev/null +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/RebuildFiles.cs @@ -0,0 +1,75 @@ +// ========================================================================== +// Squidex Headless CMS +// ========================================================================== +// Copyright (c) Squidex UG (haftungsbeschraenkt) +// All rights reserved. Licensed under the MIT license. +// ========================================================================== + +using System.IO; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using Squidex.Assets; +using Squidex.Domain.Apps.Events.Assets; +using Squidex.Infrastructure; +using Squidex.Infrastructure.EventSourcing; + +namespace Squidex.Domain.Apps.Entities.Assets +{ + public sealed class RebuildFiles + { + private static readonly MemoryStream DummyStream = new MemoryStream(Encoding.UTF8.GetBytes("dummy")); + private readonly IAssetFileStore assetFileStore; + private readonly IEventStore eventStore; + private readonly IEventDataFormatter eventDataFormatter; + + public RebuildFiles( + IAssetFileStore assetFileStore, + IEventStore eventStore, + IEventDataFormatter eventDataFormatter) + { + Guard.NotNull(assetFileStore, nameof(assetFileStore)); + Guard.NotNull(eventStore, nameof(eventStore)); + Guard.NotNull(eventDataFormatter, nameof(eventDataFormatter)); + + this.assetFileStore = assetFileStore; + this.eventStore = eventStore; + this.eventDataFormatter = eventDataFormatter; + } + + public async Task RepairAsync(CancellationToken ct = default) + { + await foreach (var storedEvent in eventStore.QueryAllAsync("^asset\\-", ct: ct)) + { + var @event = eventDataFormatter.ParseIfKnown(storedEvent); + + if (@event != null) + { + switch (@event.Payload) + { + case AssetCreated assetCreated: + await TryRepairAsync(assetCreated.AppId, assetCreated.AssetId, assetCreated.FileVersion, ct); + break; + case AssetUpdated assetUpdated: + await TryRepairAsync(assetUpdated.AppId, assetUpdated.AssetId, assetUpdated.FileVersion, ct); + break; + } + } + } + } + + private async Task TryRepairAsync(NamedId appId, DomainId id, long fileVersion, CancellationToken ct) + { + try + { + await assetFileStore.GetFileSizeAsync(appId.Id, id, fileVersion, ct); + } + catch (AssetNotFoundException) + { + DummyStream.Position = 0; + + await assetFileStore.UploadAsync(appId.Id, id, fileVersion, DummyStream, ct); + } + } + } +} diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/RecursiveDeleter.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/RecursiveDeleter.cs index cfb5baaa6..24a7b1eb2 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/RecursiveDeleter.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/RecursiveDeleter.cs @@ -88,14 +88,14 @@ namespace Squidex.Domain.Apps.Entities.Assets var appId = folderDeleted.AppId; - var childAssetFolders = await assetFolderRepository.QueryChildIdsAsync(appId.Id, folderDeleted.AssetFolderId); + var childAssetFolders = await assetFolderRepository.QueryChildIdsAsync(appId.Id, folderDeleted.AssetFolderId, default); foreach (var assetFolderId in childAssetFolders) { await PublishAsync(new DeleteAssetFolder { AppId = appId, AssetFolderId = assetFolderId }); } - var childAssets = await assetRepository.QueryChildIdsAsync(appId.Id, folderDeleted.AssetFolderId); + var childAssets = await assetRepository.QueryChildIdsAsync(appId.Id, folderDeleted.AssetFolderId, default); foreach (var assetId in childAssets) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetFolderRepository.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetFolderRepository.cs index 7d904d4e4..dac077fc7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetFolderRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetFolderRepository.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Squidex.Infrastructure; @@ -13,10 +14,10 @@ namespace Squidex.Domain.Apps.Entities.Assets.Repositories { public interface IAssetFolderRepository { - Task> QueryAsync(DomainId appId, DomainId parentId); + Task> QueryAsync(DomainId appId, DomainId parentId, CancellationToken ct = default); - Task> QueryChildIdsAsync(DomainId appId, DomainId parentId); + Task> QueryChildIdsAsync(DomainId appId, DomainId parentId, CancellationToken ct = default); - Task FindAssetFolderAsync(DomainId appId, DomainId id); + Task FindAssetFolderAsync(DomainId appId, DomainId id, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetRepository.cs b/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetRepository.cs index edcd3d1b2..5ec3cfc90 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Assets/Repositories/IAssetRepository.cs @@ -14,20 +14,20 @@ namespace Squidex.Domain.Apps.Entities.Assets.Repositories { public interface IAssetRepository { - IAsyncEnumerable StreamAll(DomainId appId, CancellationToken ct); + IAsyncEnumerable StreamAll(DomainId appId, CancellationToken ct = default); - Task> QueryAsync(DomainId appId, DomainId? parentId, Q q); + Task> QueryAsync(DomainId appId, DomainId? parentId, Q q, CancellationToken ct = default); - Task> QueryIdsAsync(DomainId appId, HashSet ids); + Task> QueryIdsAsync(DomainId appId, HashSet ids, CancellationToken ct = default); - Task> QueryChildIdsAsync(DomainId appId, DomainId parentId); + Task> QueryChildIdsAsync(DomainId appId, DomainId parentId, CancellationToken ct = default); - Task FindAssetByHashAsync(DomainId appId, string hash, string fileName, long fileSize); + Task FindAssetByHashAsync(DomainId appId, string hash, string fileName, long fileSize, CancellationToken ct = default); - Task FindAssetBySlugAsync(DomainId appId, string slug); + Task FindAssetBySlugAsync(DomainId appId, string slug, CancellationToken ct = default); - Task FindAssetAsync(DomainId appId); + Task FindAssetAsync(DomainId id, CancellationToken ct = default); - Task FindAssetAsync(DomainId appId, DomainId id); + Task FindAssetAsync(DomainId appId, DomainId id, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs b/backend/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs index 23472eed0..96cfa06ab 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Backup/BackupGrain.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -119,12 +119,14 @@ namespace Squidex.Domain.Apps.Entities.Backup Process(job, actor, currentJobToken.Token); } - private void Process(BackupJob job, RefToken actor, CancellationToken ct) + private void Process(BackupJob job, RefToken actor, + CancellationToken ct) { ProcessAsync(job, actor, ct).Forget(); } - private async Task ProcessAsync(BackupJob job, RefToken actor, CancellationToken ct) + private async Task ProcessAsync(BackupJob job, RefToken actor, + CancellationToken ct) { var handlers = CreateHandlers(); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs index dd00dd2f8..ef6f42ef0 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentSchedulerGrain.cs @@ -94,7 +94,7 @@ namespace Squidex.Domain.Apps.Entities.Contents } catch (DomainObjectNotFoundException) { - await contentRepository.ResetScheduledAsync(content.UniqueId); + await contentRepository.ResetScheduledAsync(content.UniqueId, default); } catch (Exception ex) { @@ -104,7 +104,7 @@ namespace Squidex.Domain.Apps.Entities.Contents .WriteProperty("contentId", logContentId)); } }); - }); + }, default); } public Task ReceiveReminder(string reminderName, TickStatus status) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentsSearchSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentsSearchSource.cs index 57d93e163..980837024 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentsSearchSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/ContentsSearchSource.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Text; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core.Contents; @@ -45,7 +46,8 @@ namespace Squidex.Domain.Apps.Entities.Contents this.urlGenerator = urlGenerator; } - public async Task SearchAsync(string query, Context context) + public async Task SearchAsync(string query, Context context, + CancellationToken ct) { var result = new SearchResults(); @@ -67,7 +69,7 @@ namespace Squidex.Domain.Apps.Entities.Contents var appId = context.App.NamedId(); - var contents = await contentQuery.QueryAsync(context, Q.Empty.WithIds(ids)); + var contents = await contentQuery.QueryAsync(context, Q.Empty.WithIds(ids), ct); foreach (var content in contents) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/Guards/ValidationExtensions.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/Guards/ValidationExtensions.cs index 2fc376e0b..3f57f0e02 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/Guards/ValidationExtensions.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/DomainObject/Guards/ValidationExtensions.cs @@ -94,7 +94,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject.Guards { var contentRepository = context.Resolve(); - var hasReferrer = await contentRepository.HasReferrersAsync(context.App.Id, context.ContentId, SearchScope.All); + var hasReferrer = await contentRepository.HasReferrersAsync(context.App.Id, context.ContentId, SearchScope.All, default); if (hasReferrer) { diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/IContentQueryService.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/IContentQueryService.cs index c7489031a..167204054 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/IContentQueryService.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/IContentQueryService.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Infrastructure; @@ -13,14 +14,14 @@ namespace Squidex.Domain.Apps.Entities.Contents { public interface IContentQueryService { - Task> QueryAsync(Context context, Q q); + Task> QueryAsync(Context context, Q q, CancellationToken ct = default); - Task> QueryAsync(Context context, string schemaIdOrName, Q query); + Task> QueryAsync(Context context, string schemaIdOrName, Q query, CancellationToken ct = default); - Task FindAsync(Context context, string schemaIdOrName, DomainId id, long version = EtagVersion.Any); + Task FindAsync(Context context, string schemaIdOrName, DomainId id, long version = EtagVersion.Any, CancellationToken ct = default); Task GetSchemaOrThrowAsync(Context context, string schemaIdOrName); - Task GetSchemaAsync(Context context, string schemaIdOrName); + Task GetSchemaAsync(Context context, string schemaIdOrNama); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentEnricher.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentEnricher.cs index c49b720b1..d24bf1894 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentEnricher.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentEnricher.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Infrastructure; @@ -36,24 +37,27 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries this.contentQuery = contentQuery; } - public async Task EnrichAsync(IContentEntity content, bool cloneData, Context context) + public async Task EnrichAsync(IContentEntity content, bool cloneData, Context context, + CancellationToken ct) { Guard.NotNull(content, nameof(content)); - var enriched = await EnrichInternalAsync(Enumerable.Repeat(content, 1), cloneData, context); + var enriched = await EnrichInternalAsync(Enumerable.Repeat(content, 1), cloneData, context, ct); return enriched[0]; } - public Task> EnrichAsync(IEnumerable contents, Context context) + public Task> EnrichAsync(IEnumerable contents, Context context, + CancellationToken ct) { Guard.NotNull(contents, nameof(contents)); Guard.NotNull(context, nameof(context)); - return EnrichInternalAsync(contents, false, context); + return EnrichInternalAsync(contents, false, context, ct); } - private async Task> EnrichInternalAsync(IEnumerable contents, bool cloneData, Context context) + private async Task> EnrichInternalAsync(IEnumerable contents, bool cloneData, Context context, + CancellationToken ct) { using (Profiler.TraceMethod()) { @@ -63,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { foreach (var step in steps) { - await step.EnrichAsync(context); + await step.EnrichAsync(context, ct); } } @@ -92,9 +96,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries foreach (var step in steps) { + ct.ThrowIfCancellationRequested(); + using (Profiler.TraceMethod(step.ToString()!)) { - await step.EnrichAsync(context, results, GetSchema); + await step.EnrichAsync(context, results, GetSchema, ct); } } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs index 20ca246c0..2aa1dd54f 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/ContentQueryService.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Contents.Repositories; using Squidex.Domain.Apps.Entities.Schemas; @@ -49,7 +50,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries this.queryParser = queryParser; } - public async Task FindAsync(Context context, string schemaIdOrName, DomainId id, long version = EtagVersion.Any) + public async Task FindAsync(Context context, string schemaIdOrName, DomainId id, long version = EtagVersion.Any, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); @@ -65,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries } else { - content = await contentRepository.FindContentAsync(context.App, schema, id, context.Scope()); + content = await contentRepository.FindContentAsync(context.App, schema, id, context.Scope(), ct); } if (content == null || content.SchemaId.Id != schema.Id) @@ -73,11 +75,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries return null; } - return await TransformAsync(context, content); + return await TransformAsync(context, content, ct); } } - public async Task> QueryAsync(Context context, string schemaIdOrName, Q q) + public async Task> QueryAsync(Context context, string schemaIdOrName, Q q, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); @@ -97,18 +100,19 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries q = await queryParser.ParseAsync(context, q, schema); - var contents = await contentRepository.QueryAsync(context.App, schema, q, context.Scope()); + var contents = await contentRepository.QueryAsync(context.App, schema, q, context.Scope(), ct); if (q.Ids != null && q.Ids.Count > 0) { contents = contents.SortSet(x => x.Id, q.Ids); } - return await TransformAsync(context, contents); + return await TransformAsync(context, contents, ct); } } - public async Task> QueryAsync(Context context, Q q) + public async Task> QueryAsync(Context context, Q q, + CancellationToken ct = default) { Guard.NotNull(context, nameof(context)); @@ -128,36 +132,39 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries q = await queryParser.ParseAsync(context, q); - var contents = await contentRepository.QueryAsync(context.App, schemas, q, context.Scope()); + var contents = await contentRepository.QueryAsync(context.App, schemas, q, context.Scope(), ct); if (q.Ids != null && q.Ids.Count > 0) { contents = contents.SortSet(x => x.Id, q.Ids); } - return await TransformAsync(context, contents); + return await TransformAsync(context, contents, ct); } } - private async Task> TransformAsync(Context context, IResultList contents) + private async Task> TransformAsync(Context context, IResultList contents, + CancellationToken ct) { - var transformed = await TransformCoreAsync(context, contents); + var transformed = await TransformCoreAsync(context, contents, ct); return ResultList.Create(contents.Total, transformed); } - private async Task TransformAsync(Context context, IContentEntity content) + private async Task TransformAsync(Context context, IContentEntity content, + CancellationToken ct) { - var transformed = await TransformCoreAsync(context, Enumerable.Repeat(content, 1)); + var transformed = await TransformCoreAsync(context, Enumerable.Repeat(content, 1), ct); return transformed[0]; } - private async Task> TransformCoreAsync(Context context, IEnumerable contents) + private async Task> TransformCoreAsync(Context context, IEnumerable contents, + CancellationToken ct) { using (Profiler.TraceMethod()) { - return await contentEnricher.EnrichAsync(contents, context); + return await contentEnricher.EnrichAsync(contents, context, ct); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricher.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricher.cs index 63ab1198b..74c775f4d 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricher.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricher.cs @@ -6,14 +6,15 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; namespace Squidex.Domain.Apps.Entities.Contents.Queries { public interface IContentEnricher { - Task EnrichAsync(IContentEntity content, bool cloneData, Context context); + Task EnrichAsync(IContentEntity content, bool cloneData, Context context, CancellationToken ct = default); - Task> EnrichAsync(IEnumerable contents, Context context); + Task> EnrichAsync(IEnumerable contents, Context context, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricherStep.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricherStep.cs index 82ab79b5a..e27033ada 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricherStep.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/IContentEnricherStep.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Infrastructure; @@ -16,9 +17,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries public interface IContentEnricherStep { - Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas); + Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, CancellationToken ct); - Task EnrichAsync(Context context) + Task EnrichAsync(Context context, CancellationToken ct) { return Task.CompletedTask; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ConvertData.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ConvertData.cs index 512d11ae9..655811602 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ConvertData.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ConvertData.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core.ConvertContent; @@ -49,14 +50,17 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps excludedHiddenValue = FieldConverters.ForValues(ValueConverters.ExcludeHidden); } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { - var referenceCleaner = await CleanReferencesAsync(context, contents, schemas); + var referenceCleaner = await CleanReferencesAsync(context, contents, schemas, ct); var converters = GenerateConverters(context, referenceCleaner).ToArray(); foreach (var group in contents.GroupBy(x => x.SchemaId.Id)) { + ct.ThrowIfCancellationRequested(); + var schema = await schemas(group.Key); foreach (var content in group) @@ -66,7 +70,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps } } - private async Task CleanReferencesAsync(Context context, IEnumerable contents, ProvideSchema schemas) + private async Task CleanReferencesAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { if (!context.ShouldSkipCleanup()) { @@ -85,8 +90,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps if (ids.Count > 0) { var (assets, refContents) = await AsyncHelper.WhenAll( - QueryAssetIdsAsync(context, ids), - QueryContentIdsAsync(context, ids)); + QueryAssetIdsAsync(context, ids, ct), + QueryContentIdsAsync(context, ids, ct)); var foundIds = assets.Union(refContents).ToHashSet(); @@ -97,16 +102,18 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps return null; } - private async Task> QueryContentIdsAsync(Context context, HashSet ids) + private async Task> QueryContentIdsAsync(Context context, HashSet ids, + CancellationToken ct) { - var result = await contentRepository.QueryIdsAsync(context.App.Id, ids, context.Scope()); + var result = await contentRepository.QueryIdsAsync(context.App.Id, ids, context.Scope(), ct); return result.Select(x => x.Id); } - private async Task> QueryAssetIdsAsync(Context context, HashSet ids) + private async Task> QueryAssetIdsAsync(Context context, HashSet ids, + CancellationToken ct) { - var result = await assetRepository.QueryIdsAsync(context.App.Id, ids); + var result = await assetRepository.QueryIdsAsync(context.App.Id, ids, ct); return result; } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichForCaching.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichForCaching.cs index f91c3e858..949806aef 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichForCaching.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichForCaching.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Infrastructure; using Squidex.Infrastructure.Caching; @@ -24,19 +25,23 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps this.requestCache = requestCache; } - public Task EnrichAsync(Context context) + public Task EnrichAsync(Context context, + CancellationToken ct) { context.AddCacheHeaders(requestCache); return Task.CompletedTask; } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { var app = context.App; foreach (var group in contents.GroupBy(x => x.SchemaId.Id)) { + ct.ThrowIfCancellationRequested(); + var schema = await schemas(group.Key); foreach (var content in group) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithSchema.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithSchema.cs index 120b41980..9d40e40b7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithSchema.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithSchema.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Schemas; @@ -14,10 +15,13 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps { public sealed class EnrichWithSchema : IContentEnricherStep { - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { foreach (var group in contents.GroupBy(x => x.SchemaId.Id)) { + ct.ThrowIfCancellationRequested(); + var schema = await schemas(group.Key); var schemaName = schema.SchemaDef.Name; diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithWorkflows.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithWorkflows.cs index 88f366bd2..4dda4332b 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithWorkflows.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/EnrichWithWorkflows.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Contents; using Squidex.Infrastructure; @@ -26,12 +27,15 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps this.contentWorkflow = contentWorkflow; } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { var cache = new Dictionary<(DomainId, Status), StatusInfo>(); foreach (var content in contents) { + ct.ThrowIfCancellationRequested(); + await EnrichColorAsync(content, content, cache); if (ShouldEnrichWithStatuses(context)) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveAssets.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveAssets.cs index f296aa962..f3a47f937 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveAssets.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveAssets.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core.Assets; @@ -40,7 +41,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps this.requestCache = requestCache; } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { if (ShouldEnrich(context)) { @@ -53,7 +55,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps AddAssetIds(ids, schema, group); } - var assets = await GetAssetsAsync(context, ids); + var assets = await GetAssetsAsync(context, ids, ct); foreach (var group in contents.GroupBy(x => x.SchemaId.Id)) { @@ -111,7 +113,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps } } - private async Task> GetAssetsAsync(Context context, HashSet ids) + private async Task> GetAssetsAsync(Context context, HashSet ids, + CancellationToken ct) { if (ids.Count == 0) { @@ -122,7 +125,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps .WithoutAssetEnrichment(true) .WithoutTotal()); - var assets = await assetQuery.QueryAsync(queryContext, null, Q.Empty.WithIds(ids)); + var assets = await assetQuery.QueryAsync(queryContext, null, Q.Empty.WithIds(ids), ct); return assets.ToLookup(x => x.Id); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveReferences.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveReferences.cs index fa229049f..fcaa8afd2 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveReferences.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ResolveReferences.cs @@ -1,4 +1,4 @@ -// ========================================================================== +// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Contents; using Squidex.Domain.Apps.Core.ExtractReferenceIds; @@ -41,7 +42,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps this.requestCache = requestCache; } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { if (ShouldEnrich(context)) { @@ -54,7 +56,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps AddReferenceIds(ids, schema, group); } - var references = await GetReferencesAsync(context, ids); + var references = await GetReferencesAsync(context, ids, ct); foreach (var group in contents.GroupBy(x => x.SchemaId.Id)) { @@ -65,7 +67,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps } } - private async Task ResolveReferencesAsync(Context context, ISchemaEntity schema, IEnumerable contents, ILookup references, ProvideSchema schemas) + private async Task ResolveReferencesAsync(Context context, ISchemaEntity schema, IEnumerable contents, ILookup references, + ProvideSchema schemas) { var formatted = new Dictionary(); @@ -146,7 +149,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps } } - private async Task> GetReferencesAsync(Context context, HashSet ids) + private async Task> GetReferencesAsync(Context context, HashSet ids, + CancellationToken ct) { if (ids.Count == 0) { @@ -157,7 +161,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps .WithoutContentEnrichment(true) .WithoutTotal()); - var references = await ContentQuery.QueryAsync(queryContext, Q.Empty.WithIds(ids)); + var references = await ContentQuery.QueryAsync(queryContext, Q.Empty.WithIds(ids), ct); return references.ToLookup(x => x.Id); } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ScriptContent.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ScriptContent.cs index c67fb4691..f0cf237f1 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ScriptContent.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Queries/Steps/ScriptContent.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core.Scripting; using Squidex.Infrastructure; @@ -24,7 +25,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps this.scriptEngine = scriptEngine; } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { if (ShouldEnrich(context)) { @@ -36,13 +38,14 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps if (!string.IsNullOrWhiteSpace(script)) { - await Task.WhenAll(group.Select(x => TransformAsync(context, script, x))); + await Task.WhenAll(group.Select(x => TransformAsync(context, script, x, ct))); } } } } - private async Task TransformAsync(Context context, string script, ContentEntity content) + private async Task TransformAsync(Context context, string script, ContentEntity content, + CancellationToken ct) { var vars = new ScriptVars { @@ -58,7 +61,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries.Steps AsContext = true }; - content.Data = await scriptEngine.TransformAsync(vars, script, options); + content.Data = await scriptEngine.TransformAsync(vars, script, options, ct); } private static bool ShouldEnrich(Context context) diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Repositories/IContentRepository.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Repositories/IContentRepository.cs index 66fe44a66..c42b83d8f 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Repositories/IContentRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Repositories/IContentRepository.cs @@ -20,22 +20,22 @@ namespace Squidex.Domain.Apps.Entities.Contents.Repositories { public interface IContentRepository { - IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds, CancellationToken ct); + IAsyncEnumerable StreamAll(DomainId appId, HashSet? schemaIds, CancellationToken ct = default); - Task> QueryAsync(IAppEntity app, List schemas, Q q, SearchScope scope); + Task> QueryAsync(IAppEntity app, List schemas, Q q, SearchScope scope, CancellationToken ct = default); - Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, SearchScope scope); + Task> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q, SearchScope scope, CancellationToken ct = default); - Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode); + Task> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode filterNode, CancellationToken ct = default); - Task> QueryIdsAsync(DomainId appId, HashSet ids, SearchScope scope); + Task> QueryIdsAsync(DomainId appId, HashSet ids, SearchScope scope, CancellationToken ct = default); - Task FindContentAsync(IAppEntity app, ISchemaEntity schema, DomainId id, SearchScope scope); + Task FindContentAsync(IAppEntity app, ISchemaEntity schema, DomainId id, SearchScope scope, CancellationToken ct = default); - Task HasReferrersAsync(DomainId appId, DomainId contentId, SearchScope scope); + Task HasReferrersAsync(DomainId appId, DomainId contentId, SearchScope scope, CancellationToken ct = default); - Task ResetScheduledAsync(DomainId documentId); + Task ResetScheduledAsync(DomainId documentId, CancellationToken ct = default); - Task QueryScheduledWithoutDataAsync(Instant now, Func callback); + Task QueryScheduledWithoutDataAsync(Instant now, Func callback, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Contents/Validation/DependencyValidatorsFactory.cs b/backend/src/Squidex.Domain.Apps.Entities/Contents/Validation/DependencyValidatorsFactory.cs index d5fe735f8..bedba96db 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Contents/Validation/DependencyValidatorsFactory.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Contents/Validation/DependencyValidatorsFactory.cs @@ -42,7 +42,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Validation { var checkAssets = new CheckAssets(async ids => { - return await assetRepository.QueryAsync(context.AppId.Id, null, Q.Empty.WithIds(ids)); + return await assetRepository.QueryAsync(context.AppId.Id, null, Q.Empty.WithIds(ids), default); }); yield return new AssetsValidator(isRequired, assetsField.Properties, checkAssets); @@ -52,7 +52,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Validation { var checkReferences = new CheckContentsByIds(async ids => { - return await contentRepository.QueryIdsAsync(context.AppId.Id, ids, SearchScope.All); + return await contentRepository.QueryIdsAsync(context.AppId.Id, ids, SearchScope.All, default); }); yield return new ReferencesValidator(isRequired, referencesField.Properties, checkReferences); @@ -62,7 +62,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Validation { var checkUniqueness = new CheckUniqueness(async filter => { - return await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter); + return await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter, default); }); yield return new UniqueValidator(checkUniqueness); @@ -72,7 +72,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Validation { var checkUniqueness = new CheckUniqueness(async filter => { - return await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter); + return await contentRepository.QueryIdsAsync(context.AppId.Id, context.SchemaId.Id, filter, default); }); yield return new UniqueValidator(checkUniqueness); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Rules/Repositories/IRuleEventRepository.cs b/backend/src/Squidex.Domain.Apps.Entities/Rules/Repositories/IRuleEventRepository.cs index 72f42f0d8..33c8defa3 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Rules/Repositories/IRuleEventRepository.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Rules/Repositories/IRuleEventRepository.cs @@ -48,10 +48,10 @@ namespace Squidex.Domain.Apps.Entities.Rules.Repositories Task QueryPendingAsync(Instant now, Func callback, CancellationToken ct = default); - Task> QueryStatisticsByAppAsync(DomainId appId); + Task> QueryStatisticsByAppAsync(DomainId appId, CancellationToken ct = default); - Task> QueryByAppAsync(DomainId appId, DomainId? ruleId = null, int skip = 0, int take = 20); + Task> QueryByAppAsync(DomainId appId, DomainId? ruleId = null, int skip = 0, int take = 20, CancellationToken ct = default); - Task FindAsync(DomainId id); + Task FindAsync(DomainId id, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemasSearchSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemasSearchSource.cs index 1329d98b1..1540fe36e 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemasSearchSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Schemas/SchemasSearchSource.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using Squidex.Domain.Apps.Core; using Squidex.Domain.Apps.Core.Schemas; @@ -31,7 +32,8 @@ namespace Squidex.Domain.Apps.Entities.Schemas this.urlGenerator = urlGenerator; } - public async Task SearchAsync(string query, Context context) + public async Task SearchAsync(string query, Context context, + CancellationToken ct) { var result = new SearchResults(); diff --git a/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchManager.cs b/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchManager.cs index 2843f05fe..7bb95ddd8 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchManager.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchManager.cs @@ -5,12 +5,13 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; namespace Squidex.Domain.Apps.Entities.Search { public interface ISearchManager { - Task SearchAsync(string? query, Context context); + Task SearchAsync(string? query, Context context, CancellationToken ct = default); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchSource.cs b/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchSource.cs index 368a2c5e0..60c82eac7 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchSource.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Search/ISearchSource.cs @@ -5,12 +5,13 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; namespace Squidex.Domain.Apps.Entities.Search { public interface ISearchSource { - Task SearchAsync(string query, Context context); + Task SearchAsync(string query, Context context, CancellationToken ct); } } diff --git a/backend/src/Squidex.Domain.Apps.Entities/Search/SearchManager.cs b/backend/src/Squidex.Domain.Apps.Entities/Search/SearchManager.cs index 317bfc9aa..c8fbe8fcd 100644 --- a/backend/src/Squidex.Domain.Apps.Entities/Search/SearchManager.cs +++ b/backend/src/Squidex.Domain.Apps.Entities/Search/SearchManager.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using Squidex.Infrastructure; using Squidex.Log; @@ -30,25 +31,27 @@ namespace Squidex.Domain.Apps.Entities.Search this.log = log; } - public async Task SearchAsync(string? query, Context context) + public async Task SearchAsync(string? query, Context context, + CancellationToken ct = default) { if (string.IsNullOrWhiteSpace(query) || query.Length < 3) { return new SearchResults(); } - var tasks = searchSources.Select(x => SearchAsync(x, query, context)); + var tasks = searchSources.Select(x => SearchAsync(x, query, context, ct)); var results = await Task.WhenAll(tasks); return new SearchResults(results.SelectMany(x => x)); } - private async Task SearchAsync(ISearchSource source, string query, Context context) + private async Task SearchAsync(ISearchSource source, string query, Context context, + CancellationToken ct) { try { - return await source.SearchAsync(query, context); + return await source.SearchAsync(query, context, ct); } catch (Exception ex) { diff --git a/backend/src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs b/backend/src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs index fce5a8629..76cca2f06 100644 --- a/backend/src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs +++ b/backend/src/Squidex.Domain.Users.MongoDb/MongoRoleStore.cs @@ -41,7 +41,8 @@ namespace Squidex.Domain.Users.MongoDb return "Identity_Roles"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { return collection.Indexes.CreateOneAsync( new CreateIndexModel( @@ -123,4 +124,4 @@ namespace Squidex.Domain.Users.MongoDb return Task.CompletedTask; } } -} \ No newline at end of file +} diff --git a/backend/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs b/backend/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs index 8404f8ac7..d348d3d25 100644 --- a/backend/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs +++ b/backend/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs @@ -138,7 +138,8 @@ namespace Squidex.Domain.Users.MongoDb return "Identity_Users"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { return collection.Indexes.CreateManyAsync(new[] { @@ -601,4 +602,4 @@ namespace Squidex.Domain.Users.MongoDb return Task.FromResult(false); } } -} \ No newline at end of file +} diff --git a/backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs b/backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs index 092087016..aa0ad9aa4 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs +++ b/backend/src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore.cs @@ -53,7 +53,8 @@ namespace Squidex.Infrastructure.EventSourcing return new MongoCollectionSettings { WriteConcern = WriteConcern.WMajority }; } - protected override async Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override async Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { await collection.Indexes.CreateManyAsync(new[] { diff --git a/backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequestLogRepository.cs b/backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequestLogRepository.cs index 3f58ed89c..14f353afa 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequestLogRepository.cs +++ b/backend/src/Squidex.Infrastructure.MongoDb/Log/MongoRequestLogRepository.cs @@ -34,7 +34,8 @@ namespace Squidex.Infrastructure.Log return "RequestLog"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct = default) { return collection.Indexes.CreateManyAsync(new[] { diff --git a/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs b/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs index 5ace1d1fd..de3a9b1f3 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs +++ b/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoRepositoryBase.cs @@ -84,7 +84,8 @@ namespace Squidex.Infrastructure.MongoDb return string.Format(CultureInfo.InvariantCulture, CollectionFormat, typeof(TEntity).Name); } - protected virtual Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected virtual Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct) { return Task.CompletedTask; } @@ -131,4 +132,4 @@ namespace Squidex.Infrastructure.MongoDb CollectionSettings() ?? new MongoCollectionSettings()); } } -} \ No newline at end of file +} diff --git a/backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs b/backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs index 358117b13..26b41a69b 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs +++ b/backend/src/Squidex.Infrastructure.MongoDb/UsageTracking/MongoUsageRepository.cs @@ -29,7 +29,8 @@ namespace Squidex.Infrastructure.UsageTracking return "UsagesV2"; } - protected override Task SetupCollectionAsync(IMongoCollection collection, CancellationToken ct = default) + protected override Task SetupCollectionAsync(IMongoCollection collection, + CancellationToken ct = default) { return collection.Indexes.CreateOneAsync( new CreateIndexModel( @@ -37,7 +38,7 @@ namespace Squidex.Infrastructure.UsageTracking .Ascending(x => x.Key) .Ascending(x => x.Category) .Ascending(x => x.Date)), - cancellationToken: ct); + cancellationToken: ct = default); } public async Task TrackUsagesAsync(UsageUpdate update) diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs index cecbb6cf8..cf46e4fe1 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetContentController.cs @@ -76,11 +76,11 @@ namespace Squidex.Areas.Api.Controllers.Assets { var requestContext = Context.Clone(b => b.WithoutAssetEnrichment()); - var asset = await assetQuery.FindAsync(requestContext, DomainId.Create(idOrSlug)); + var asset = await assetQuery.FindAsync(requestContext, DomainId.Create(idOrSlug), ct: HttpContext.RequestAborted); if (asset == null) { - asset = await assetQuery.FindBySlugAsync(requestContext, idOrSlug); + asset = await assetQuery.FindBySlugAsync(requestContext, idOrSlug, HttpContext.RequestAborted); } return await DeliverAssetAsync(requestContext, asset, request); @@ -106,7 +106,7 @@ namespace Squidex.Areas.Api.Controllers.Assets { var requestContext = Context.Clone(b => b.WithoutAssetEnrichment()); - var asset = await assetQuery.FindGlobalAsync(requestContext, id); + var asset = await assetQuery.FindGlobalAsync(requestContext, id, HttpContext.RequestAborted); return await DeliverAssetAsync(requestContext, asset, request); } @@ -131,7 +131,7 @@ namespace Squidex.Areas.Api.Controllers.Assets { if (context.App != null) { - asset = await assetQuery.FindAsync(context, asset.Id, request.Version); + asset = await assetQuery.FindAsync(context, asset.Id, request.Version, HttpContext.RequestAborted); } else { @@ -265,4 +265,4 @@ namespace Squidex.Areas.Api.Controllers.Assets FileOptions.SequentialScan); } } -} \ No newline at end of file +} diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetFoldersController.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetFoldersController.cs index 852edeb73..7a18acd7c 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetFoldersController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetFoldersController.cs @@ -54,8 +54,8 @@ namespace Squidex.Areas.Api.Controllers.Assets public async Task GetAssetFolders(string app, [FromQuery] DomainId parentId) { var (folders, path) = await AsyncHelper.WhenAll( - assetQuery.QueryAssetFoldersAsync(Context, parentId), - assetQuery.FindAssetFolderAsync(Context.App.Id, parentId)); + assetQuery.QueryAssetFoldersAsync(Context, parentId, HttpContext.RequestAborted), + assetQuery.FindAssetFolderAsync(Context.App.Id, parentId, HttpContext.RequestAborted)); var response = Deferred.Response(() => { diff --git a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetsController.cs b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetsController.cs index d04bcd6cc..0500445b8 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetsController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Assets/AssetsController.cs @@ -98,7 +98,7 @@ namespace Squidex.Areas.Api.Controllers.Assets [ApiCosts(1)] public async Task GetAssets(string app, [FromQuery] DomainId? parentId, [FromQuery] string? ids = null, [FromQuery] string? q = null) { - var assets = await assetQuery.QueryAsync(Context, parentId, CreateQuery(ids, q)); + var assets = await assetQuery.QueryAsync(Context, parentId, CreateQuery(ids, q), HttpContext.RequestAborted); var response = Deferred.Response(() => { @@ -127,7 +127,7 @@ namespace Squidex.Areas.Api.Controllers.Assets [ApiCosts(1)] public async Task GetAssetsPost(string app, [FromBody] QueryDto query) { - var assets = await assetQuery.QueryAsync(Context, query?.ParentId, query?.ToQuery() ?? Q.Empty); + var assets = await assetQuery.QueryAsync(Context, query?.ParentId, query?.ToQuery() ?? Q.Empty, HttpContext.RequestAborted); var response = Deferred.Response(() => { @@ -153,7 +153,7 @@ namespace Squidex.Areas.Api.Controllers.Assets [ApiCosts(1)] public async Task GetAsset(string app, DomainId id) { - var asset = await assetQuery.FindAsync(Context, id); + var asset = await assetQuery.FindAsync(Context, id, ct: HttpContext.RequestAborted); if (asset == null) { diff --git a/backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs b/backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs index 334948465..e5e96f344 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Contents/ContentsController.cs @@ -83,7 +83,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetAllContents(string app, [FromQuery] string ids) { - var contents = await contentQuery.QueryAsync(Context, Q.Empty.WithIds(ids)); + var contents = await contentQuery.QueryAsync(Context, Q.Empty.WithIds(ids), HttpContext.RequestAborted); var response = Deferred.AsyncResponse(() => { @@ -112,7 +112,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetAllContentsPost(string app, [FromBody] ContentsIdsQueryDto query) { - var contents = await contentQuery.QueryAsync(Context, Q.Empty.WithIds(query.Ids)); + var contents = await contentQuery.QueryAsync(Context, Q.Empty.WithIds(query.Ids), HttpContext.RequestAborted); var response = Deferred.AsyncResponse(() => { @@ -143,7 +143,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetContents(string app, string schema, [FromQuery] string? ids = null, [FromQuery] string? q = null) { - var contents = await contentQuery.QueryAsync(Context, schema, CreateQuery(ids, q)); + var contents = await contentQuery.QueryAsync(Context, schema, CreateQuery(ids, q), HttpContext.RequestAborted); var response = Deferred.AsyncResponse(() => { @@ -173,7 +173,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetContentsPost(string app, string schema, [FromBody] QueryDto query) { - var contents = await contentQuery.QueryAsync(Context, schema, query?.ToQuery() ?? Q.Empty); + var contents = await contentQuery.QueryAsync(Context, schema, query?.ToQuery() ?? Q.Empty, HttpContext.RequestAborted); var response = Deferred.AsyncResponse(() => { @@ -203,7 +203,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetContent(string app, string schema, DomainId id) { - var content = await contentQuery.FindAsync(Context, schema, id); + var content = await contentQuery.FindAsync(Context, schema, id, ct: HttpContext.RequestAborted); if (content == null) { @@ -263,7 +263,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetReferences(string app, string schema, DomainId id, [FromQuery] string? q = null) { - var contents = await contentQuery.QueryAsync(Context, CreateQuery(null, q).WithReferencing(id)); + var contents = await contentQuery.QueryAsync(Context, CreateQuery(null, q).WithReferencing(id), HttpContext.RequestAborted); var response = Deferred.AsyncResponse(() => { @@ -294,7 +294,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetReferencing(string app, string schema, DomainId id, [FromQuery] string? q = null) { - var contents = await contentQuery.QueryAsync(Context, CreateQuery(null, q).WithReference(id)); + var contents = await contentQuery.QueryAsync(Context, CreateQuery(null, q).WithReference(id), HttpContext.RequestAborted); var response = Deferred.AsyncResponse(() => { @@ -324,7 +324,7 @@ namespace Squidex.Areas.Api.Controllers.Contents [ApiCosts(1)] public async Task GetContentVersion(string app, string schema, DomainId id, int version) { - var content = await contentQuery.FindAsync(Context, schema, id, version); + var content = await contentQuery.FindAsync(Context, schema, id, version, HttpContext.RequestAborted); if (content == null) { diff --git a/backend/src/Squidex/Areas/Api/Controllers/Search/SearchController.cs b/backend/src/Squidex/Areas/Api/Controllers/Search/SearchController.cs index 10d41b551..0d7e6bcca 100644 --- a/backend/src/Squidex/Areas/Api/Controllers/Search/SearchController.cs +++ b/backend/src/Squidex/Areas/Api/Controllers/Search/SearchController.cs @@ -47,7 +47,7 @@ namespace Squidex.Areas.Api.Controllers.Search [ApiCosts(0)] public async Task GetSearchResults(string app, [FromQuery] string? query = null) { - var result = await searchManager.SearchAsync(query, Context); + var result = await searchManager.SearchAsync(query, Context, HttpContext.RequestAborted); var response = result.Select(SearchResultDto.FromSearchResult).ToArray(); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppSettingsSearchSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppSettingsSearchSourceTests.cs index 5e6df30d8..ebeb7fb15 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppSettingsSearchSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Apps/AppSettingsSearchSourceTests.cs @@ -35,7 +35,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("xyz", ctx); + var result = await sut.SearchAsync("xyz", ctx, default); Assert.Empty(result); } @@ -50,7 +50,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.DashboardUI(appId)) .Returns("dashboard-url"); - var result = await sut.SearchAsync("dashboard", ctx); + var result = await sut.SearchAsync("dashboard", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -62,7 +62,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("assets", ctx); + var result = await sut.SearchAsync("assets", ctx, default); Assert.Empty(result); } @@ -77,7 +77,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.LanguagesUI(appId)) .Returns("languages-url"); - var result = await sut.SearchAsync("languages", ctx); + var result = await sut.SearchAsync("languages", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("assets", ctx); + var result = await sut.SearchAsync("assets", ctx, default); Assert.Empty(result); } @@ -99,7 +99,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("patterns", ctx); + var result = await sut.SearchAsync("patterns", ctx, default); Assert.Empty(result); } @@ -114,7 +114,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.SchemasUI(appId)) .Returns("schemas-url"); - var result = await sut.SearchAsync("schemas", ctx); + var result = await sut.SearchAsync("schemas", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -126,7 +126,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("schemas", ctx); + var result = await sut.SearchAsync("schemas", ctx, default); Assert.Empty(result); } @@ -141,7 +141,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.AssetsUI(appId, A._)) .Returns("assets-url"); - var result = await sut.SearchAsync("assets", ctx); + var result = await sut.SearchAsync("assets", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -153,7 +153,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("assets", ctx); + var result = await sut.SearchAsync("assets", ctx, default); Assert.Empty(result); } @@ -168,7 +168,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.BackupsUI(appId)) .Returns("backups-url"); - var result = await sut.SearchAsync("backups", ctx); + var result = await sut.SearchAsync("backups", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -180,7 +180,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("backups", ctx); + var result = await sut.SearchAsync("backups", ctx, default); Assert.Empty(result); } @@ -195,7 +195,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.ClientsUI(appId)) .Returns("clients-url"); - var result = await sut.SearchAsync("clients", ctx); + var result = await sut.SearchAsync("clients", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -207,7 +207,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("clients", ctx); + var result = await sut.SearchAsync("clients", ctx, default); Assert.Empty(result); } @@ -222,7 +222,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.ContributorsUI(appId)) .Returns("contributors-url"); - var result = await sut.SearchAsync("contributors", ctx); + var result = await sut.SearchAsync("contributors", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -234,7 +234,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("contributors", ctx); + var result = await sut.SearchAsync("contributors", ctx, default); Assert.Empty(result); } @@ -249,7 +249,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.PlansUI(appId)) .Returns("subscription-url"); - var result = await sut.SearchAsync("subscription", ctx); + var result = await sut.SearchAsync("subscription", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -261,7 +261,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("subscription", ctx); + var result = await sut.SearchAsync("subscription", ctx, default); Assert.Empty(result); } @@ -276,7 +276,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.RolesUI(appId)) .Returns("roles-url"); - var result = await sut.SearchAsync("roles", ctx); + var result = await sut.SearchAsync("roles", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -288,7 +288,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("roles", ctx); + var result = await sut.SearchAsync("roles", ctx, default); Assert.Empty(result); } @@ -303,7 +303,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.RulesUI(appId)) .Returns("rules-url"); - var result = await sut.SearchAsync("rules", ctx); + var result = await sut.SearchAsync("rules", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -315,7 +315,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("assets", ctx); + var result = await sut.SearchAsync("assets", ctx, default); Assert.Empty(result); } @@ -330,7 +330,7 @@ namespace Squidex.Domain.Apps.Entities.Apps A.CallTo(() => urlGenerator.WorkflowsUI(appId)) .Returns("workflows-url"); - var result = await sut.SearchAsync("workflows", ctx); + var result = await sut.SearchAsync("workflows", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -342,7 +342,7 @@ namespace Squidex.Domain.Apps.Entities.Apps { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("workflows", ctx); + var result = await sut.SearchAsync("workflows", ctx, default); Assert.Empty(result); } @@ -360,4 +360,4 @@ namespace Squidex.Domain.Apps.Entities.Apps return new Context(claimsPrincipal, Mocks.App(appId)); } } -} \ No newline at end of file +} diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs index 4a8c01e30..095354905 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsFluidExtensionTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Microsoft.Extensions.DependencyInjection; @@ -62,10 +63,10 @@ namespace Squidex.Domain.Apps.Entities.Assets AppId = appId }; - A.CallTo(() => assetQuery.FindAsync(A._, assetId1, EtagVersion.Any)) + A.CallTo(() => assetQuery.FindAsync(A._, assetId1, EtagVersion.Any, A._)) .Returns(asset1); - A.CallTo(() => assetQuery.FindAsync(A._, assetId2, EtagVersion.Any)) + A.CallTo(() => assetQuery.FindAsync(A._, assetId2, EtagVersion.Any, A._)) .Returns(asset2); var vars = new TemplateVars diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs index dfd309a1c..3dbc6fb6e 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsJintExtensionTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Microsoft.Extensions.Caching.Memory; @@ -62,7 +63,7 @@ namespace Squidex.Domain.Apps.Entities.Assets .AddInvariant(JsonValue.Array(assetId1))); A.CallTo(() => assetQuery.QueryAsync( - A.That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A.That.HasIds(assetId1))) + A.That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A.That.HasIds(assetId1), A._)) .Returns(ResultList.CreateFrom(1, asset1)); var vars = new ScriptVars { Data = data, AppId = appId.Id, User = user }; @@ -100,7 +101,7 @@ namespace Squidex.Domain.Apps.Entities.Assets .AddInvariant(JsonValue.Array(assetId1, assetId2))); A.CallTo(() => assetQuery.QueryAsync( - A.That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A.That.HasIds(assetId1, assetId2))) + A.That.Matches(x => x.App.Id == appId.Id && x.User == user), null, A.That.HasIds(assetId1, assetId2), A._)) .Returns(ResultList.CreateFrom(2, asset1, asset2)); var vars = new ScriptVars { Data = data, AppId = appId.Id, User = user }; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsSearchSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsSearchSourceTests.cs index 146eafb67..729e2c6fb 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsSearchSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/AssetsSearchSourceTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using FluentAssertions; @@ -36,11 +37,11 @@ namespace Squidex.Domain.Apps.Entities.Assets { var ctx = ContextWithPermission(); - var result = await sut.SearchAsync("logo", ctx); + var result = await sut.SearchAsync("logo", ctx, default); Assert.Empty(result); - A.CallTo(() => assetQuery.QueryAsync(A._, A._, A._)) + A.CallTo(() => assetQuery.QueryAsync(A._, A._, A._, A._)) .MustNotHaveHappened(); } @@ -57,10 +58,10 @@ namespace Squidex.Domain.Apps.Entities.Assets A.CallTo(() => urlGenerator.AssetsUI(appId, "logo")) .Returns("assets-url"); - A.CallTo(() => assetQuery.QueryAsync(ctx, null, A.That.HasQuery("Filter: contains(fileName, 'logo'); Take: 5"))) + A.CallTo(() => assetQuery.QueryAsync(ctx, null, A.That.HasQuery("Filter: contains(fileName, 'logo'); Take: 5"), A._)) .Returns(ResultList.CreateFrom(2, asset1, asset2)); - var result = await sut.SearchAsync("logo", ctx); + var result = await sut.SearchAsync("logo", ctx, default); result.Should().BeEquivalentTo( new SearchResults() diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/BackupAssetsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/BackupAssetsTests.cs index a40cfc29f..54a0a633f 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/BackupAssetsTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/BackupAssetsTests.cs @@ -229,7 +229,7 @@ namespace Squidex.Domain.Apps.Entities.Assets var rebuildAssets = new HashSet(); A.CallTo(() => rebuilder.InsertManyAsync(A>._, A._, A._)) - .Invokes((IEnumerable source, CancellationToken _) => rebuildAssets.AddRange(source)); + .Invokes((IEnumerable source, int _, CancellationToken _) => rebuildAssets.AddRange(source)); await sut.RestoreAsync(context); @@ -266,7 +266,7 @@ namespace Squidex.Domain.Apps.Entities.Assets var rebuildAssetFolders = new HashSet(); A.CallTo(() => rebuilder.InsertManyAsync(A>._, A._, A._)) - .Invokes((IEnumerable source, CancellationToken _) => rebuildAssetFolders.AddRange(source)); + .Invokes((IEnumerable source, int _, CancellationToken _) => rebuildAssetFolders.AddRange(source)); await sut.RestoreAsync(context); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetCommandMiddlewareTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetCommandMiddlewareTests.cs index 969a9b9ae..e57d07ace 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetCommandMiddlewareTests.cs @@ -50,7 +50,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject A.CallTo(() => contextProvider.Context) .Returns(requestContext); - A.CallTo(() => assetQuery.FindByHashAsync(A._, A._, A._, A._)) + A.CallTo(() => assetQuery.FindByHashAsync(A._, A._, A._, A._, A._)) .Returns(Task.FromResult(null)); sut = new AssetCommandMiddleware(grainFactory, @@ -65,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject { await HandleAsync(new AnnotateAsset(), 12); - A.CallTo(() => assetEnricher.EnrichAsync(A._, requestContext)) + A.CallTo(() => assetEnricher.EnrichAsync(A._, requestContext, A._)) .MustNotHaveHappened(); } @@ -78,7 +78,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject await HandleAsync(new AnnotateAsset(), result); - A.CallTo(() => assetEnricher.EnrichAsync(A._, requestContext)) + A.CallTo(() => assetEnricher.EnrichAsync(A._, requestContext, A._)) .MustNotHaveHappened(); } @@ -89,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject var enriched = new AssetEntity(); - A.CallTo(() => assetEnricher.EnrichAsync(result, requestContext)) + A.CallTo(() => assetEnricher.EnrichAsync(result, requestContext, A._)) .Returns(enriched); var context = @@ -206,7 +206,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject FileSize = fileSize }; - A.CallTo(() => assetQuery.FindByHashAsync(requestContext, A._, fileName, fileSize)) + A.CallTo(() => assetQuery.FindByHashAsync(requestContext, A._, fileName, fileSize, A._)) .Returns(duplicate); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetDomainObjectTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetDomainObjectTests.cs index 52f732e3c..8d04f9918 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetDomainObjectTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetDomainObjectTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Assets; @@ -40,7 +41,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject public AssetDomainObjectTests() { - A.CallTo(() => assetQuery.FindAssetFolderAsync(AppId, parentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(AppId, parentId, A._)) .Returns(new List { A.Fake() }); A.CallTo(() => tagService.NormalizeTagsAsync(AppId, TagGroups.Assets, A>._, A>._)) @@ -330,7 +331,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject await ExecuteCreateAsync(); - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id, SearchScope.All, A._)) .Returns(true); var result = await PublishAsync(command); @@ -348,7 +349,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject await ExecuteCreateAsync(); - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id, SearchScope.All, A._)) .Returns(true); await Assert.ThrowsAsync(() => PublishAsync(command)); @@ -361,7 +362,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject await ExecuteCreateAsync(); - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, Id, SearchScope.All, A._)) .Returns(true); await PublishAsync(command); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetFolderDomainObjectTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetFolderDomainObjectTests.cs index 8236e3dfe..f75dea987 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetFolderDomainObjectTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/AssetFolderDomainObjectTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Entities.Assets.Commands; @@ -31,7 +32,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject public AssetFolderDomainObjectTests() { - A.CallTo(() => assetQuery.FindAssetFolderAsync(AppId, parentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(AppId, parentId, A._)) .Returns(new List { A.Fake() }); sut = new AssetFolderDomainObject(PersistenceFactory, A.Dummy(), assetQuery); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetFolderTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetFolderTests.cs index 4d7be8a6c..786f81315 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetFolderTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetFolderTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core.TestHelpers; @@ -27,7 +28,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards { var command = new CreateAssetFolder { AppId = appId }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A._)) .Returns(new List()); await ValidationAssert.ThrowsAsync(() => GuardAssetFolder.CanCreate(command, assetQuery), @@ -39,7 +40,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards { var command = new CreateAssetFolder { AppId = appId, FolderName = "My Folder", ParentId = DomainId.NewGuid() }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A._)) .Returns(new List()); await ValidationAssert.ThrowsAsync(() => GuardAssetFolder.CanCreate(command, assetQuery), @@ -51,7 +52,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards { var command = new CreateAssetFolder { AppId = appId, FolderName = "My Folder", ParentId = DomainId.NewGuid() }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A._)) .Returns(new List { AssetFolder() }); await GuardAssetFolder.CanCreate(command, assetQuery); @@ -72,7 +73,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards var command = new MoveAssetFolder { AppId = appId, ParentId = DomainId.NewGuid() }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A._)) .Returns(new List { AssetFolder(id), @@ -88,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards { var command = new MoveAssetFolder { AppId = appId, ParentId = DomainId.NewGuid() }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A._)) .Returns(new List()); await ValidationAssert.ThrowsAsync(() => GuardAssetFolder.CanMove(command, AssetFolder(), assetQuery), @@ -100,7 +101,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards { var command = new MoveAssetFolder { AppId = appId, ParentId = DomainId.NewGuid() }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, A._)) .Returns(new List { AssetFolder() }); await GuardAssetFolder.CanMove(command, AssetFolder(), assetQuery); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetTests.cs index 978d7fe3d..bc1e7df57 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/DomainObject/Guards/GuardAssetTests.cs @@ -32,7 +32,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards var command = new MoveAsset { AppId = appId, ParentId = parentId }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, parentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, parentId, default)) .Returns(new List()); await ValidationAssert.ThrowsAsync(() => GuardAsset.CanMove(command, Asset(), assetQuery), @@ -46,7 +46,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards var command = new MoveAsset { AppId = appId, ParentId = parentId, OptimizeValidation = true }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, default)) .Returns(new List()); await GuardAsset.CanMove(command, Asset(), assetQuery); @@ -59,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards var command = new MoveAsset { AppId = appId, ParentId = parentId }; - A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId)) + A.CallTo(() => assetQuery.FindAssetFolderAsync(appId.Id, command.ParentId, default)) .Returns(new List { AssetFolder() }); await GuardAsset.CanMove(command, Asset(), assetQuery); @@ -90,7 +90,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.DomainObject.Guards var command = new DeleteAsset { AppId = appId, CheckReferrers = true }; - A.CallTo(() => contentRepository.HasReferrersAsync(appId.Id, asset.Id, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(appId.Id, asset.Id, SearchScope.All, default)) .Returns(true); await Assert.ThrowsAsync(() => GuardAsset.CanDelete(command, asset, contentRepository)); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetEnricherTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetEnricherTests.cs index 46aa6c307..5a8cc0b66 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetEnricherTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetEnricherTests.cs @@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var source = new AssetEntity { AppId = appId }; - var result = await sut.EnrichAsync(source, requestContext); + var result = await sut.EnrichAsync(source, requestContext, default); Assert.Empty(result.TagNames); } @@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var source = new AssetEntity { AppId = appId, Id = DomainId.NewGuid(), Version = 13 }; - var result = await sut.EnrichAsync(source, requestContext); + var result = await sut.EnrichAsync(source, requestContext, default); A.CallTo(() => requestCache.AddDependency(result.UniqueId, result.Version)) .MustHaveHappened(); @@ -81,7 +81,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries ["id2"] = "name2" }); - var result = await sut.EnrichAsync(source, requestContext); + var result = await sut.EnrichAsync(source, requestContext, default); Assert.Equal(new HashSet { "name1", "name2" }, result.TagNames); } @@ -99,7 +99,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries AppId = appId }; - var result = await sut.EnrichAsync(source, requestContext.Clone(b => b.WithoutAssetEnrichment())); + var result = await sut.EnrichAsync(source, requestContext.Clone(b => b.WithoutAssetEnrichment()), default); Assert.Null(result.TagNames); } @@ -124,7 +124,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries A.CallTo(() => assetMetadataSource2.Format(A._)) .Returns(new[] { "metadata2", "metadata3" }); - var result = await sut.EnrichAsync(source, requestContext); + var result = await sut.EnrichAsync(source, requestContext, default); Assert.Equal("metadata1, metadata2, metadata3, 2 kB", result.MetadataText); } @@ -160,7 +160,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries ["id3"] = "name3" }); - var result = await sut.EnrichAsync(new[] { source1, source2 }, requestContext); + var result = await sut.EnrichAsync(new[] { source1, source2 }, requestContext, default); Assert.Equal(new HashSet { "name1", "name2" }, result[0].TagNames); Assert.Equal(new HashSet { "name2", "name3" }, result[1].TagNames); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetQueryServiceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetQueryServiceTests.cs index 1f486a5b1..0a3ce49ec 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetQueryServiceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/Queries/AssetQueryServiceTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Entities.Assets.Repositories; @@ -45,7 +46,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetBySlugAsync(appId.Id, "slug")) + A.CallTo(() => assetRepository.FindAssetBySlugAsync(appId.Id, "slug", A._)) .Returns(asset); var result = await sut.FindBySlugAsync(requestContext, "slug"); @@ -58,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetBySlugAsync(appId.Id, "slug")) + A.CallTo(() => assetRepository.FindAssetBySlugAsync(appId.Id, "slug", A._)) .Returns(Task.FromResult(null)); var result = await sut.FindBySlugAsync(requestContext, "slug"); @@ -71,7 +72,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetAsync(appId.Id, asset.Id)) + A.CallTo(() => assetRepository.FindAssetAsync(appId.Id, asset.Id, A._)) .Returns(asset); var result = await sut.FindAsync(requestContext, asset.Id); @@ -84,7 +85,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetAsync(appId.Id, asset.Id)) + A.CallTo(() => assetRepository.FindAssetAsync(appId.Id, asset.Id, A._)) .Returns(Task.FromResult(null)); var result = await sut.FindAsync(requestContext, asset.Id); @@ -123,7 +124,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetAsync(asset.Id)) + A.CallTo(() => assetRepository.FindAssetAsync(asset.Id, A._)) .Returns(asset); var result = await sut.FindGlobalAsync(requestContext, asset.Id); @@ -136,7 +137,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetAsync(asset.Id)) + A.CallTo(() => assetRepository.FindAssetAsync(asset.Id, A._)) .Returns(Task.FromResult(null)); var result = await sut.FindGlobalAsync(requestContext, asset.Id); @@ -149,7 +150,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetByHashAsync(appId.Id, "hash", "name", 123)) + A.CallTo(() => assetRepository.FindAssetByHashAsync(appId.Id, "hash", "name", 123, A._)) .Returns(asset); var result = await sut.FindByHashAsync(requestContext, "hash", "name", 123); @@ -162,7 +163,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var asset = CreateAsset(DomainId.NewGuid()); - A.CallTo(() => assetRepository.FindAssetByHashAsync(appId.Id, "hash", "name", 123)) + A.CallTo(() => assetRepository.FindAssetByHashAsync(appId.Id, "hash", "name", 123, A._)) .Returns(Task.FromResult(null)); var result = await sut.FindByHashAsync(requestContext, "hash", "name", 123); @@ -180,7 +181,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var q = Q.Empty.WithODataQuery("fileName eq 'Name'"); - A.CallTo(() => assetRepository.QueryAsync(appId.Id, parentId, q)) + A.CallTo(() => assetRepository.QueryAsync(appId.Id, parentId, q, A._)) .Returns(ResultList.CreateFrom(8, asset1, asset2)); var result = await sut.QueryAsync(requestContext, parentId, q); @@ -198,7 +199,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var assetFolders = ResultList.CreateFrom(10); - A.CallTo(() => assetFolderRepository.QueryAsync(appId.Id, parentId)) + A.CallTo(() => assetFolderRepository.QueryAsync(appId.Id, parentId, A._)) .Returns(assetFolders); var result = await sut.QueryAssetFoldersAsync(requestContext, parentId); @@ -213,7 +214,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var assetFolders = ResultList.CreateFrom(10); - A.CallTo(() => assetFolderRepository.QueryAsync(appId.Id, parentId)) + A.CallTo(() => assetFolderRepository.QueryAsync(appId.Id, parentId, A._)) .Returns(assetFolders); var result = await sut.QueryAssetFoldersAsync(appId.Id, parentId); @@ -227,7 +228,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var folderId1 = DomainId.NewGuid(); var folder1 = CreateFolder(folderId1); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1, A._)) .Returns(folder1); var result = await sut.FindAssetFolderAsync(appId.Id, folderId1); @@ -246,13 +247,13 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var folder2 = CreateFolder(folderId2, folderId1); var folder3 = CreateFolder(folderId3, folderId2); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1, A._)) .Returns(folder1); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId2)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId2, A._)) .Returns(folder2); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId3)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId3, A._)) .Returns(folder3); var result = await sut.FindAssetFolderAsync(appId.Id, folderId3); @@ -265,7 +266,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries { var folderId1 = DomainId.NewGuid(); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1, A._)) .Returns(Task.FromResult(null)); var result = await sut.FindAssetFolderAsync(appId.Id, folderId1); @@ -282,10 +283,10 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var folder1 = CreateFolder(folderId1); var folder2 = CreateFolder(folderId2, folderId1); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1, A._)) .Returns(Task.FromResult(null)); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId2)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId2, A._)) .Returns(folder2); var result = await sut.FindAssetFolderAsync(appId.Id, folderId2); @@ -302,10 +303,10 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries var folder1 = CreateFolder(folderId1, folderId2); var folder2 = CreateFolder(folderId2, folderId1); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId1, A._)) .Returns(Task.FromResult(null)); - A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId2)) + A.CallTo(() => assetFolderRepository.FindAssetFolderAsync(appId.Id, folderId2, A._)) .Returns(folder2); var result = await sut.FindAssetFolderAsync(appId.Id, folderId2); @@ -337,7 +338,7 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries private void SetupEnricher() { - A.CallTo(() => assetEnricher.EnrichAsync(A>._, A._)) + A.CallTo(() => assetEnricher.EnrichAsync(A>._, A._, A._)) .ReturnsLazily(x => { var input = x.GetArgument>(0)!; @@ -346,4 +347,4 @@ namespace Squidex.Domain.Apps.Entities.Assets.Queries }); } } -} \ No newline at end of file +} diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/RecursiveDeleterTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/RecursiveDeleterTests.cs index 21118de20..f5bf834a4 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/RecursiveDeleterTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Assets/RecursiveDeleterTests.cs @@ -7,6 +7,7 @@ using System; using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Entities.Assets.Commands; @@ -80,7 +81,7 @@ namespace Squidex.Domain.Apps.Entities.Assets var childFolderId1 = DomainId.NewGuid(); var childFolderId2 = DomainId.NewGuid(); - A.CallTo(() => assetFolderRepository.QueryChildIdsAsync(appId.Id, @event.AssetFolderId)) + A.CallTo(() => assetFolderRepository.QueryChildIdsAsync(appId.Id, @event.AssetFolderId, A._)) .Returns(new List { childFolderId1, childFolderId2 }); await sut.On(Envelope.Create(@event)); @@ -100,7 +101,7 @@ namespace Squidex.Domain.Apps.Entities.Assets var childId1 = DomainId.NewGuid(); var childId2 = DomainId.NewGuid(); - A.CallTo(() => assetRepository.QueryChildIdsAsync(appId.Id, @event.AssetFolderId)) + A.CallTo(() => assetRepository.QueryChildIdsAsync(appId.Id, @event.AssetFolderId, A._)) .Returns(new List { childId1, childId2 }); await sut.On(Envelope.Create(@event)); @@ -123,7 +124,7 @@ namespace Squidex.Domain.Apps.Entities.Assets A.CallTo(() => commandBus.PublishAsync(A.That.Matches(x => x.AssetId == childId1))) .Throws(new InvalidOperationException()); - A.CallTo(() => assetRepository.QueryChildIdsAsync(appId.Id, @event.AssetFolderId)) + A.CallTo(() => assetRepository.QueryChildIdsAsync(appId.Id, @event.AssetFolderId, A._)) .Returns(new List { childId1, childId2 }); await sut.On(Envelope.Create(@event)); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/BackupContentsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/BackupContentsTests.cs index bd7ecfdb4..3e40f0441 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/BackupContentsTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/BackupContentsTests.cs @@ -193,7 +193,7 @@ namespace Squidex.Domain.Apps.Entities.Contents var rebuildContents = new HashSet(); A.CallTo(() => rebuilder.InsertManyAsync(A>._, A._, A._)) - .Invokes((IEnumerable source, CancellationToken _) => rebuildContents.AddRange(source)); + .Invokes((IEnumerable source, int _, CancellationToken _) => rebuildContents.AddRange(source)); await sut.RestoreAsync(context); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentsSearchSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentsSearchSourceTests.cs index 444e9f4fc..2a3335b91 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentsSearchSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ContentsSearchSourceTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using FluentAssertions; @@ -155,7 +156,7 @@ namespace Squidex.Domain.Apps.Entities.Contents { var ctx = ContextWithPermissions(); - var result = await sut.SearchAsync("query", ctx); + var result = await sut.SearchAsync("query", ctx, default); Assert.Empty(result); @@ -171,11 +172,11 @@ namespace Squidex.Domain.Apps.Entities.Contents A.CallTo(() => contentIndex.SearchAsync(ctx.App, A.That.Matches(x => x.Text == "query~"), ctx.Scope())) .Returns(new List()); - var result = await sut.SearchAsync("query", ctx); + var result = await sut.SearchAsync("query", ctx, default); Assert.Empty(result); - A.CallTo(() => contentQuery.QueryAsync(ctx, A._)) + A.CallTo(() => contentQuery.QueryAsync(ctx, A._, A._)) .MustNotHaveHappened(); } @@ -190,13 +191,13 @@ namespace Squidex.Domain.Apps.Entities.Contents A.CallTo(() => contentIndex.SearchAsync(ctx.App, A.That.Matches(x => x.Text == "query~" && x.Filter != null), ctx.Scope())) .Returns(ids); - A.CallTo(() => contentQuery.QueryAsync(ctx, A.That.HasIds(ids))) + A.CallTo(() => contentQuery.QueryAsync(ctx, A.That.HasIds(ids), A._)) .Returns(ResultList.CreateFrom(1, content)); A.CallTo(() => urlGenerator.ContentUI(appId, schemaId1, content.Id)) .Returns("content-url"); - var result = await sut.SearchAsync("query", ctx); + var result = await sut.SearchAsync("query", ctx, default); result.Should().BeEquivalentTo( new SearchResults() diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentCommandMiddlewareTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentCommandMiddlewareTests.cs index fc8eb2f33..c7d6ebb82 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentCommandMiddlewareTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Orleans; @@ -51,7 +52,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject { await HandleAsync(new CreateContent(), 12); - A.CallTo(() => contentEnricher.EnrichAsync(A._, A._, requestContext)) + A.CallTo(() => contentEnricher.EnrichAsync(A._, A._, requestContext, A._)) .MustNotHaveHappened(); } @@ -66,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject Assert.Same(result, context.Result()); - A.CallTo(() => contentEnricher.EnrichAsync(A._, A._, requestContext)) + A.CallTo(() => contentEnricher.EnrichAsync(A._, A._, requestContext, A._)) .MustNotHaveHappened(); } @@ -77,7 +78,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject var enriched = new ContentEntity(); - A.CallTo(() => contentEnricher.EnrichAsync(result, true, requestContext)) + A.CallTo(() => contentEnricher.EnrichAsync(result, true, requestContext, A._)) .Returns(enriched); var context = diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentDomainObjectTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentDomainObjectTests.cs index 9ce9c22f0..75a52f5ea 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentDomainObjectTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentDomainObjectTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Microsoft.Extensions.DependencyInjection; @@ -100,7 +101,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject A.CallTo(() => appProvider.GetAppWithSchemaAsync(AppId, SchemaId, false)) .Returns((app, schema)); - A.CallTo(() => scriptEngine.TransformAsync(A._, A._, ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, A._, ScriptOptions(), default)) .ReturnsLazily(x => Task.FromResult(x.GetArgument(0)!.Data!)); patched = patch.MergeInto(data); @@ -148,9 +149,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentCreated { Data = data, Status = Status.Draft }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -171,9 +172,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentCreated { Data = data, Status = Status.Draft }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -195,9 +196,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -248,9 +249,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentCreated { Data = data, Status = Status.Draft }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -271,9 +272,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentCreated { Data = data, Status = Status.Draft }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -295,9 +296,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -319,7 +320,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentUpdated { Data = otherData }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -341,7 +342,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentUpdated { Data = otherData }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -365,9 +366,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, null, Status.Archived, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, null, Status.Archived, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -421,7 +422,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentUpdated { Data = otherData }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -445,7 +446,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentUpdated { Data = otherData }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(otherData, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -462,7 +463,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject Assert.Single(LastEvents); - A.CallTo(() => scriptEngine.TransformAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -494,7 +495,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentUpdated { Data = patched }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(patched, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(patched, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -518,7 +519,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentUpdated { Data = patched }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(patched, data, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(patched, data, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -535,7 +536,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject Assert.Single(LastEvents); - A.CallTo(() => scriptEngine.TransformAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -557,7 +558,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -579,7 +580,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -602,7 +603,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Draft, Change = StatusChange.Unpublished }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft, Status.Published), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft, Status.Published), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -611,7 +612,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject { var command = new ChangeContentStatus { Status = Status.Draft }; - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft, Status.Published), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft, Status.Published), "", ScriptOptions(), default)) .Returns(otherData); await ExecuteCreateAsync(); @@ -630,7 +631,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Draft, Change = StatusChange.Unpublished }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft, Status.Published), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Draft, Status.Published), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -654,7 +655,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Change = StatusChange.Change, Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Archived, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -678,7 +679,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Change = StatusChange.Published, Status = Status.Published }) ); - A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Published, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(ScriptVars(data, null, Status.Published, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -705,7 +706,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusScheduled { Status = Status.Published, DueTime = dueTime }) ); - A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -733,7 +734,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentStatusChanged { Status = Status.Archived }) ); - A.CallTo(() => scriptEngine.TransformAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -761,7 +762,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentSchedulingCancelled()) ); - A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(A._, "", ScriptOptions(), default)) .MustNotHaveHappened(); } @@ -773,7 +774,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject await ExecuteCreateAsync(); await ExecuteChangeStatusAsync(Status.Published); - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All, A._)) .Returns(true); await Assert.ThrowsAsync(() => PublishAsync(command)); @@ -787,7 +788,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject await ExecuteCreateAsync(); await ExecuteChangeStatusAsync(Status.Published); - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.Published)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.Published, A._)) .Returns(true); await PublishAsync(command); @@ -823,7 +824,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject CreateContentEvent(new ContentDeleted()) ); - A.CallTo(() => scriptEngine.ExecuteAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -841,7 +842,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject Assert.Equal(EtagVersion.Empty, sut.Snapshot.Version); Assert.Empty(LastEvents); - A.CallTo(() => scriptEngine.ExecuteAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions())) + A.CallTo(() => scriptEngine.ExecuteAsync(ScriptVars(data, null, Status.Draft), "", ScriptOptions(), default)) .MustHaveHappened(); } @@ -852,7 +853,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject var command = new DeleteContent { CheckReferrers = true }; - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All, A._)) .Returns(true); await Assert.ThrowsAsync(() => PublishAsync(command)); @@ -865,7 +866,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject await ExecuteCreateAsync(); - A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All)) + A.CallTo(() => contentRepository.HasReferrersAsync(AppId, contentId, SearchScope.All, A._)) .Returns(true); await PublishAsync(command); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentsBulkUpdateCommandMiddlewareTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentsBulkUpdateCommandMiddlewareTests.cs index 1379fa343..f7a1c2067 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentsBulkUpdateCommandMiddlewareTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/DomainObject/ContentsBulkUpdateCommandMiddlewareTests.cs @@ -7,6 +7,7 @@ using System; using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using NodaTime; @@ -88,7 +89,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject x.ShouldSkipCleanup() && x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), - schemaId.Name, A.That.Matches(x => x.JsonQuery == query))) + schemaId.Name, A.That.Matches(x => x.JsonQuery == query), A._)) .Returns(ResultList.CreateFrom(2, CreateContent(id), CreateContent(id))); var command = BulkCommand(BulkUpdateContentType.ChangeStatus, query); @@ -114,7 +115,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject x.ShouldSkipCleanup() && x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), - schemaId.Name, A.That.Matches(x => x.JsonQuery == query))) + schemaId.Name, A.That.Matches(x => x.JsonQuery == query), A._)) .Returns(ResultList.CreateFrom(1, CreateContent(id))); var command = BulkCommand(BulkUpdateContentType.Upsert, query: query, data: data); @@ -144,7 +145,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.DomainObject x.ShouldSkipCleanup() && x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), - schemaId.Name, A.That.Matches(x => x.JsonQuery == query))) + schemaId.Name, A.That.Matches(x => x.JsonQuery == query), A._)) .Returns(ResultList.CreateFrom(2, CreateContent(id1), CreateContent(id2))); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs index de1bfd16d..08f360c30 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/GraphQL/GraphQLQueriesTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using GraphQL; @@ -60,7 +61,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL var asset = TestAsset.Create(appId, DomainId.NewGuid()); A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query" && x.NoTotal == true))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query" && x.NoTotal == true), A._)) .Returns(ResultList.CreateFrom(0, asset)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -95,7 +96,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL var asset = TestAsset.Create(appId, DomainId.NewGuid()); A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query" && x.NoTotal == false))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5&$filter=my-query" && x.NoTotal == false), A._)) .Returns(ResultList.CreateFrom(10, asset)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -130,7 +131,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", assetId); - A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A.That.HasIdsWithoutTotal(assetId))) + A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A.That.HasIdsWithoutTotal(assetId), A._)) .Returns(ResultList.CreateFrom(1)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -159,7 +160,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", assetId); - A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A.That.HasIdsWithoutTotal(assetId))) + A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A.That.HasIdsWithoutTotal(assetId), A._)) .Returns(ResultList.CreateFrom(1, asset)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -211,7 +212,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL var content = TestContent.Create(appId, schemaId, DomainId.NewGuid(), DomainId.Empty, DomainId.Empty); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(), - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == true))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == true), A._)) .Returns(ResultList.CreateFrom(0, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -290,7 +291,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL var content = TestContent.Create(appId, schemaId, DomainId.NewGuid(), DomainId.Empty, DomainId.Empty); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(), - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == true))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == true), A._)) .Returns(ResultList.CreateFrom(0, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -325,7 +326,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL var content = TestContent.Create(appId, schemaId, DomainId.NewGuid(), DomainId.Empty, DomainId.Empty); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(), - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == false))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.NoTotal == false), A._)) .Returns(ResultList.CreateFrom(10, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -360,7 +361,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId), A._)) .Returns(ResultList.CreateFrom(1)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -389,7 +390,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId), A._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -418,7 +419,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.FindAsync(MatchsContentContext(), schemaId.Id.ToString(), contentId, 3)) + A.CallTo(() => contentQuery.FindAsync(MatchsContentContext(), schemaId.Id.ToString(), contentId, 3, A._)) .Returns(content); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -462,10 +463,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId), A._)) .Returns(ResultList.CreateFrom(0, contentRef)); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId), A._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -528,11 +529,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentRefId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId), A._)) .Returns(ResultList.CreateFrom(1, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), content.SchemaId.Id.ToString(), - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.Reference == contentRefId && x.NoTotal == true))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.Reference == contentRefId && x.NoTotal == true), A._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -592,11 +593,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentRefId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId), A._)) .Returns(ResultList.CreateFrom(1, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), content.SchemaId.Id.ToString(), - A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.Reference == contentRefId && x.NoTotal == false))) + A.That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.Reference == contentRefId && x.NoTotal == false), A._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -666,10 +667,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentRefId), A._)) .Returns(ResultList.CreateFrom(0, contentRef)); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId), A._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -732,10 +733,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId), A._)) .Returns(ResultList.CreateFrom(1, content)); - A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A.That.HasIdsWithoutTotal(assetRefId))) + A.CallTo(() => assetQuery.QueryAsync(MatchsAssetContext(), null, A.That.HasIdsWithoutTotal(assetRefId), A._)) .Returns(ResultList.CreateFrom(0, assetRef)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); @@ -791,7 +792,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL } }", contentId); - A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId))) + A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A.That.HasIdsWithoutTotal(contentId), A._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentEnricherTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentEnricherTests.cs index 59d3ab974..225d8bbc7 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentEnricherTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentEnricherTests.cs @@ -8,6 +8,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core.Contents; @@ -30,7 +31,8 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { public ISchemaEntity Schema { get; private set; } - public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas) + public async Task EnrichAsync(Context context, IEnumerable contents, ProvideSchema schemas, + CancellationToken ct) { foreach (var group in contents.GroupBy(x => x.SchemaId.Id)) { @@ -59,18 +61,18 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var sut = new ContentEnricher(new[] { step1, step2 }, new Lazy(() => contentQuery)); - await sut.EnrichAsync(source, requestContext); + await sut.EnrichAsync(source, requestContext, default); - A.CallTo(() => step1.EnrichAsync(requestContext)) + A.CallTo(() => step1.EnrichAsync(requestContext, A._)) .MustHaveHappened(); - A.CallTo(() => step2.EnrichAsync(requestContext)) + A.CallTo(() => step2.EnrichAsync(requestContext, A._)) .MustHaveHappened(); - A.CallTo(() => step1.EnrichAsync(requestContext, A>._, A._)) + A.CallTo(() => step1.EnrichAsync(requestContext, A>._, A._, A._)) .MustNotHaveHappened(); - A.CallTo(() => step2.EnrichAsync(requestContext, A>._, A._)) + A.CallTo(() => step2.EnrichAsync(requestContext, A>._, A._, A._)) .MustNotHaveHappened(); } @@ -84,18 +86,18 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var sut = new ContentEnricher(new[] { step1, step2 }, new Lazy(() => contentQuery)); - await sut.EnrichAsync(source, false, requestContext); + await sut.EnrichAsync(source, false, requestContext, default); - A.CallTo(() => step1.EnrichAsync(requestContext)) + A.CallTo(() => step1.EnrichAsync(requestContext, A._)) .MustHaveHappened(); - A.CallTo(() => step2.EnrichAsync(requestContext)) + A.CallTo(() => step2.EnrichAsync(requestContext, A._)) .MustHaveHappened(); - A.CallTo(() => step1.EnrichAsync(requestContext, A>._, A._)) + A.CallTo(() => step1.EnrichAsync(requestContext, A>._, A._, A._)) .MustHaveHappened(); - A.CallTo(() => step2.EnrichAsync(requestContext, A>._, A._)) + A.CallTo(() => step2.EnrichAsync(requestContext, A>._, A._, A._)) .MustHaveHappened(); } @@ -109,7 +111,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var sut = new ContentEnricher(new[] { step1, step2 }, new Lazy(() => contentQuery)); - await sut.EnrichAsync(source, false, requestContext); + await sut.EnrichAsync(source, false, requestContext, default); Assert.Same(schema, step1.Schema); Assert.Same(schema, step1.Schema); @@ -125,7 +127,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var sut = new ContentEnricher(Enumerable.Empty(), new Lazy(() => contentQuery)); - var result = await sut.EnrichAsync(source, true, requestContext); + var result = await sut.EnrichAsync(source, true, requestContext, default); Assert.NotSame(source.Data, result.Data); } @@ -137,7 +139,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var sut = new ContentEnricher(Enumerable.Empty(), new Lazy(() => contentQuery)); - var result = await sut.EnrichAsync(source, false, requestContext); + var result = await sut.EnrichAsync(source, false, requestContext, default); Assert.Same(source.Data, result.Data); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentQueryServiceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentQueryServiceTests.cs index a1006965a..e20aee9d3 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentQueryServiceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ContentQueryServiceTests.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core.Contents; @@ -113,7 +114,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = CreateContent(DomainId.NewGuid()); - A.CallTo(() => contentRepository.FindContentAsync(requestContext.App, schema, content.Id, A._)) + A.CallTo(() => contentRepository.FindContentAsync(requestContext.App, schema, content.Id, A._, A._)) .Returns(CreateContent(DomainId.NewGuid())); await Assert.ThrowsAsync(() => sut.FindAsync(requestContext, schemaId.Name, content.Id)); @@ -126,7 +127,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = CreateContent(DomainId.NewGuid()); - A.CallTo(() => contentRepository.FindContentAsync(requestContext.App, schema, content.Id, A._)) + A.CallTo(() => contentRepository.FindContentAsync(requestContext.App, schema, content.Id, A._, A._)) .Returns(null); Assert.Null(await sut.FindAsync(requestContext, schemaId.Name, content.Id)); @@ -143,7 +144,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = CreateContent(DomainId.NewGuid()); - A.CallTo(() => contentRepository.FindContentAsync(requestContext.App, schema, content.Id, scope)) + A.CallTo(() => contentRepository.FindContentAsync(requestContext.App, schema, content.Id, scope, A._)) .Returns(content); var result = await sut.FindAsync(requestContext, schemaId.Name, content.Id); @@ -171,7 +172,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { var requestContext = CreateContext(allowSchema: false); - await Assert.ThrowsAsync(() => sut.QueryAsync(requestContext, schemaId.Name, Q.Empty)); + await Assert.ThrowsAsync(() => sut.QueryAsync(requestContext, schemaId.Name, Q.Empty, default)); } [Theory] @@ -188,10 +189,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var q = Q.Empty.WithReference(DomainId.NewGuid()); - A.CallTo(() => contentRepository.QueryAsync(requestContext.App, schema, q, scope)) + A.CallTo(() => contentRepository.QueryAsync(requestContext.App, schema, q, scope, A._)) .Returns(ResultList.CreateFrom(5, content1, content2)); - var result = await sut.QueryAsync(requestContext, schemaId.Name, q); + var result = await sut.QueryAsync(requestContext, schemaId.Name, q, default); Assert.Equal(5, result.Total); @@ -215,10 +216,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var q = Q.Empty.WithIds(ids); A.CallTo(() => contentRepository.QueryAsync(requestContext.App, - A>.That.Matches(x => x.Count == 1), q, scope)) + A>.That.Matches(x => x.Count == 1), q, scope, A._)) .Returns(ResultList.Create(5, contents)); - var result = await sut.QueryAsync(requestContext, q); + var result = await sut.QueryAsync(requestContext, q, default); Assert.Equal(5, result.Total); @@ -238,10 +239,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var q = Q.Empty.WithIds(ids); A.CallTo(() => contentRepository.QueryAsync(requestContext.App, - A>.That.Matches(x => x.Count == 0), q, SearchScope.All)) + A>.That.Matches(x => x.Count == 0), q, SearchScope.All, A._)) .Returns(ResultList.Create(0, ids.Select(CreateContent))); - var result = await sut.QueryAsync(requestContext, q); + var result = await sut.QueryAsync(requestContext, q, default); Assert.Empty(result); } @@ -251,10 +252,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { var requestContext = CreateContext(permissionId: Permissions.AppContentsReadOwn); - await sut.QueryAsync(requestContext, schemaId.Name, Q.Empty); + await sut.QueryAsync(requestContext, schemaId.Name, Q.Empty, default); A.CallTo(() => contentRepository.QueryAsync(requestContext.App, schema, - A.That.Matches(x => Equals(x.CreatedBy, requestContext.User.Token())), SearchScope.Published)) + A.That.Matches(x => Equals(x.CreatedBy, requestContext.User.Token())), SearchScope.Published, A._)) .MustHaveHappened(); } @@ -263,16 +264,16 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { var requestContext = CreateContext(permissionId: Permissions.AppContentsRead); - await sut.QueryAsync(requestContext, schemaId.Name, Q.Empty); + await sut.QueryAsync(requestContext, schemaId.Name, Q.Empty, default); A.CallTo(() => contentRepository.QueryAsync(requestContext.App, schema, - A.That.Matches(x => x.CreatedBy == null), SearchScope.Published)) + A.That.Matches(x => x.CreatedBy == null), SearchScope.Published, A._)) .MustHaveHappened(); } private void SetupEnricher() { - A.CallTo(() => contentEnricher.EnrichAsync(A>._, A._)) + A.CallTo(() => contentEnricher.EnrichAsync(A>._, A._, A._)) .ReturnsLazily(x => { var input = x.GetArgument>(0)!; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ConvertDataTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ConvertDataTests.cs index b048c7f07..4a35ff594 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ConvertDataTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ConvertDataTests.cs @@ -7,6 +7,7 @@ using System.Collections.Generic; using System.Linq; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core; @@ -58,7 +59,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId)); - await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider); + await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider, default); Assert.NotNull(content.Data); } @@ -88,15 +89,15 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries JsonValue.Object() .Add("nested", JsonValue.Array(id2))))); - A.CallTo(() => assetRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2))) + A.CallTo(() => assetRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2), A._)) .Returns(new List { id2 }); - A.CallTo(() => contentRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2), SearchScope.All)) + A.CallTo(() => contentRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2), SearchScope.All, A._)) .Returns(new List<(DomainId, DomainId, Status)> { (id2, id2, Status.Published) }); var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId)); - await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider); + await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider, default); Assert.Equal(expected, content.Data); } @@ -126,15 +127,15 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries JsonValue.Object() .Add("nested", JsonValue.Array())))); - A.CallTo(() => assetRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2))) + A.CallTo(() => assetRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2), A._)) .Returns(new List()); - A.CallTo(() => contentRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2), SearchScope.All)) + A.CallTo(() => contentRepository.QueryIdsAsync(appId.Id, A>.That.Is(id1, id2), SearchScope.All, A._)) .Returns(new List<(DomainId, DomainId, Status)>()); var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId)); - await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider); + await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider, default); Assert.Equal(expected, content.Data); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichForCachingTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichForCachingTests.cs index e780b1be3..d06a3f327 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichForCachingTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichForCachingTests.cs @@ -47,7 +47,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries A.CallTo(() => requestCache.AddHeader(A._)) .Invokes(new Action(header => headers.Add(header))); - await sut.EnrichAsync(requestContext); + await sut.EnrichAsync(requestContext, default); Assert.Equal(new List { @@ -67,7 +67,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { var content = CreateContent(); - await sut.EnrichAsync(requestContext, Enumerable.Repeat(content, 1), schemaProvider); + await sut.EnrichAsync(requestContext, Enumerable.Repeat(content, 1), schemaProvider, default); A.CallTo(() => requestCache.AddDependency(content.UniqueId, content.Version)) .MustHaveHappened(); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithSchemaTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithSchemaTests.cs index 60167e82a..2084f78b5 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithSchemaTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithSchemaTests.cs @@ -38,7 +38,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = CreateContent(); - await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider); + await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider, default); Assert.NotNull(content.ReferenceFields); } @@ -50,7 +50,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var source = CreateContent(); - await sut.EnrichAsync(ctx, Enumerable.Repeat(source, 1), schemaProvider); + await sut.EnrichAsync(ctx, Enumerable.Repeat(source, 1), schemaProvider, default); Assert.Null(source.ReferenceFields); } @@ -62,7 +62,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = CreateContent(); - await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider); + await sut.EnrichAsync(ctx, Enumerable.Repeat(content, 1), schemaProvider, default); Assert.Equal("my-schema", content.SchemaName); Assert.Equal("my-schema", content.SchemaDisplayName); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithWorkflowsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithWorkflowsTests.cs index 9537e0ba2..0a816b120 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithWorkflowsTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/EnrichWithWorkflowsTests.cs @@ -45,7 +45,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries A.CallTo(() => workflow.GetNextAsync(content, content.Status, requestContext.User)) .Returns(nexts); - await sut.EnrichAsync(requestContext, new[] { content }, null!); + await sut.EnrichAsync(requestContext, new[] { content }, null!, default); Assert.Equal(nexts, content.NextStatuses); } @@ -55,7 +55,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { var content = new ContentEntity { SchemaId = schemaId, IsSingleton = true, Status = Status.Draft }; - await sut.EnrichAsync(requestContext, new[] { content }, null!); + await sut.EnrichAsync(requestContext, new[] { content }, null!, default); Assert.Equal(Status.Published, content.NextStatuses?.Single().Status); @@ -68,7 +68,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries { var content = new ContentEntity { SchemaId = schemaId, IsSingleton = true, Status = Status.Published }; - await sut.EnrichAsync(requestContext, new[] { content }, null!); + await sut.EnrichAsync(requestContext, new[] { content }, null!, default); Assert.Empty(content.NextStatuses); @@ -84,7 +84,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries A.CallTo(() => workflow.GetInfoAsync(content, content.Status)) .Returns(new StatusInfo(Status.Published, StatusColors.Published)); - await sut.EnrichAsync(requestContext, new[] { content }, null!); + await sut.EnrichAsync(requestContext, new[] { content }, null!, default); Assert.Equal(StatusColors.Published, content.StatusColor); } @@ -97,7 +97,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries A.CallTo(() => workflow.GetInfoAsync(content, content.NewStatus.Value)) .Returns(new StatusInfo(Status.Published, StatusColors.Archived)); - await sut.EnrichAsync(requestContext, new[] { content }, null!); + await sut.EnrichAsync(requestContext, new[] { content }, null!, default); Assert.Equal(StatusColors.Archived, content.NewStatusColor); } @@ -110,7 +110,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries A.CallTo(() => workflow.GetInfoAsync(content, content.ScheduleJob.Status)) .Returns(new StatusInfo(Status.Published, StatusColors.Archived)); - await sut.EnrichAsync(requestContext, new[] { content }, null!); + await sut.EnrichAsync(requestContext, new[] { content }, null!, default); Assert.Equal(StatusColors.Archived, content.ScheduledStatusColor); } @@ -125,7 +125,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = requestContext.Clone(b => b.WithResolveFlow(false)); - await sut.EnrichAsync(ctx, new[] { content }, null!); + await sut.EnrichAsync(ctx, new[] { content }, null!, default); Assert.Equal(StatusColors.Draft, content.StatusColor); } @@ -140,7 +140,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = requestContext.Clone(b => b.WithResolveFlow(false)); - await sut.EnrichAsync(ctx, new[] { content }, null!); + await sut.EnrichAsync(ctx, new[] { content }, null!, default); Assert.True(content.CanUpdate); } @@ -152,7 +152,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId)).Clone(b => b.WithResolveFlow(false)); - await sut.EnrichAsync(ctx, new[] { content }, null!); + await sut.EnrichAsync(ctx, new[] { content }, null!, default); Assert.False(content.CanUpdate); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveAssetsTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveAssetsTests.cs index 7f7fa6499..b2a2ab6b0 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveAssetsTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveAssetsTests.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core; @@ -89,10 +90,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries }; A.CallTo(() => assetQuery.QueryAsync( - A.That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A.That.HasIds(doc1.Id, doc2.Id))) + A.That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A.That.HasIds(doc1.Id, doc2.Id), A._)) .Returns(ResultList.CreateFrom(4, doc1, doc2)); - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); A.CallTo(() => requestCache.AddDependency(doc1.UniqueId, doc1.Version)) .MustHaveHappened(); @@ -121,10 +122,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries }; A.CallTo(() => assetQuery.QueryAsync( - A.That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A.That.HasIds(doc1.Id, doc2.Id, img1.Id, img2.Id))) + A.That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A.That.HasIds(doc1.Id, doc2.Id, img1.Id, img2.Id), A._)) .Returns(ResultList.CreateFrom(4, img1, img2, doc1, doc2)); - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); Assert.Equal( new ContentData() @@ -157,11 +158,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId)); - await sut.EnrichAsync(ctx, contents, schemaProvider); + await sut.EnrichAsync(ctx, contents, schemaProvider, default); Assert.Null(contents[0].ReferenceData); - A.CallTo(() => assetQuery.QueryAsync(A._, null, A._)) + A.CallTo(() => assetQuery.QueryAsync(A._, null, A._, A._)) .MustNotHaveHappened(); } @@ -175,11 +176,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId)).Clone(b => b.WithoutContentEnrichment(true)); - await sut.EnrichAsync(ctx, contents, schemaProvider); + await sut.EnrichAsync(ctx, contents, schemaProvider, default); Assert.Null(contents[0].ReferenceData); - A.CallTo(() => assetQuery.QueryAsync(A._, null, A._)) + A.CallTo(() => assetQuery.QueryAsync(A._, null, A._, A._)) .MustNotHaveHappened(); } @@ -191,11 +192,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries CreateContent(Array.Empty(), Array.Empty()) }; - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); Assert.NotNull(contents[0].ReferenceData); - A.CallTo(() => assetQuery.QueryAsync(A._, null, A._)) + A.CallTo(() => assetQuery.QueryAsync(A._, null, A._, A._)) .MustNotHaveHappened(); } @@ -210,12 +211,12 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries CreateContent(new[] { id1, id2 }, Array.Empty()) }; - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); Assert.NotNull(contents[0].ReferenceData); A.CallTo(() => assetQuery.QueryAsync( - A.That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A.That.HasIds(id1))) + A.That.Matches(x => x.ShouldSkipAssetEnrichment() && x.ShouldSkipTotal()), null, A.That.HasIds(id1), A._)) .MustHaveHappened(); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveReferencesTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveReferencesTests.cs index 5fd6299c2..7bf072584 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveReferencesTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ResolveReferencesTests.cs @@ -7,6 +7,7 @@ using System; using System.Linq; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core; @@ -102,10 +103,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries }; A.CallTo(() => contentQuery.QueryAsync( - A.That.Matches(x => x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), A.That.HasIds(ref1_1.Id, ref1_2.Id, ref2_1.Id, ref2_2.Id))) + A.That.Matches(x => x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), A.That.HasIds(ref1_1.Id, ref1_2.Id, ref2_1.Id, ref2_2.Id), A._)) .Returns(ResultList.CreateFrom(4, ref1_1, ref1_2, ref2_1, ref2_2)); - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); A.CallTo(() => requestCache.AddDependency(DomainId.Combine(appId, refSchemaId1.Id), 0)) .MustHaveHappened(); @@ -141,10 +142,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries }; A.CallTo(() => contentQuery.QueryAsync( - A.That.Matches(x => x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), A.That.HasIds(ref1_1.Id, ref1_2.Id, ref2_1.Id, ref2_2.Id))) + A.That.Matches(x => x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), A.That.HasIds(ref1_1.Id, ref1_2.Id, ref2_1.Id, ref2_2.Id), A._)) .Returns(ResultList.CreateFrom(4, ref1_1, ref1_2, ref2_1, ref2_2)); - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); Assert.Equal( new ContentData() @@ -194,10 +195,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries }; A.CallTo(() => contentQuery.QueryAsync( - A.That.Matches(x => x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), A.That.HasIds(ref1_1.Id, ref1_2.Id, ref2_1.Id, ref2_2.Id))) + A.That.Matches(x => x.ShouldSkipContentEnrichment() && x.ShouldSkipTotal()), A.That.HasIds(ref1_1.Id, ref1_2.Id, ref2_1.Id, ref2_2.Id), A._)) .Returns(ResultList.CreateFrom(4, ref1_1, ref1_2, ref2_1, ref2_2)); - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); Assert.Equal( new ContentData() @@ -242,11 +243,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = new Context(Mocks.ApiUser(), Mocks.App(appId)); - await sut.EnrichAsync(ctx, contents, schemaProvider); + await sut.EnrichAsync(ctx, contents, schemaProvider, default); Assert.Null(contents[0].ReferenceData); - A.CallTo(() => contentQuery.QueryAsync(A._, A._)) + A.CallTo(() => contentQuery.QueryAsync(A._, A._, A._)) .MustNotHaveHappened(); } @@ -260,11 +261,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var ctx = new Context(Mocks.FrontendUser(), Mocks.App(appId)).Clone(b => b.WithoutContentEnrichment(true)); - await sut.EnrichAsync(ctx, contents, schemaProvider); + await sut.EnrichAsync(ctx, contents, schemaProvider, default); Assert.Null(contents[0].ReferenceData); - A.CallTo(() => contentQuery.QueryAsync(A._, A._)) + A.CallTo(() => contentQuery.QueryAsync(A._, A._, A._)) .MustNotHaveHappened(); } @@ -276,11 +277,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries CreateContent(Array.Empty(), Array.Empty()) }; - await sut.EnrichAsync(requestContext, contents, schemaProvider); + await sut.EnrichAsync(requestContext, contents, schemaProvider, default); Assert.NotNull(contents[0].ReferenceData); - A.CallTo(() => contentQuery.QueryAsync(A._, A._)) + A.CallTo(() => contentQuery.QueryAsync(A._, A._, A._)) .MustNotHaveHappened(); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ScriptContentTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ScriptContentTests.cs index a7ab3dbf9..c074b384c 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ScriptContentTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Queries/ScriptContentTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Squidex.Domain.Apps.Core.Contents; @@ -63,9 +64,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = new ContentEntity { SchemaId = schemaId }; - await sut.EnrichAsync(ctx, new[] { content }, schemaProvider); + await sut.EnrichAsync(ctx, new[] { content }, schemaProvider, default); - A.CallTo(() => scriptEngine.TransformAsync(A._, A._, ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, A._, ScriptOptions(), A._)) .MustNotHaveHappened(); } @@ -76,9 +77,9 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = new ContentEntity { SchemaId = schemaWithScriptId }; - await sut.EnrichAsync(ctx, new[] { content }, schemaProvider); + await sut.EnrichAsync(ctx, new[] { content }, schemaProvider, default); - A.CallTo(() => scriptEngine.TransformAsync(A._, A._, ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, A._, ScriptOptions(), A._)) .MustNotHaveHappened(); } @@ -91,10 +92,10 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries var content = new ContentEntity { SchemaId = schemaWithScriptId, Data = oldData }; - A.CallTo(() => scriptEngine.TransformAsync(A._, "my-query", ScriptOptions())) + A.CallTo(() => scriptEngine.TransformAsync(A._, "my-query", ScriptOptions(), A._)) .Returns(new ContentData()); - await sut.EnrichAsync(ctx, new[] { content }, schemaProvider); + await sut.EnrichAsync(ctx, new[] { content }, schemaProvider, default); Assert.NotSame(oldData, content.Data); @@ -104,7 +105,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.Queries ReferenceEquals(x.Data, oldData) && x.ContentId == content.Id), "my-query", - ScriptOptions())) + ScriptOptions(), A._)) .MustHaveHappened(); } diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesFluidExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesFluidExtensionTests.cs index ba04132d6..3df3d5681 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesFluidExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesFluidExtensionTests.cs @@ -5,6 +5,7 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Microsoft.Extensions.DependencyInjection; @@ -62,10 +63,10 @@ namespace Squidex.Domain.Apps.Entities.Contents AppId = appId }; - A.CallTo(() => contentQuery.QueryAsync(A._, A.That.HasIds(referenceId1))) + A.CallTo(() => contentQuery.QueryAsync(A._, A.That.HasIds(referenceId1), A._)) .Returns(ResultList.CreateFrom(1, reference1)); - A.CallTo(() => contentQuery.QueryAsync(A._, A.That.HasIds(referenceId2))) + A.CallTo(() => contentQuery.QueryAsync(A._, A.That.HasIds(referenceId2), A._)) .Returns(ResultList.CreateFrom(1, reference2)); var vars = new TemplateVars diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesJintExtensionTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesJintExtensionTests.cs index a25b0de22..76a500838 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesJintExtensionTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Contents/ReferencesJintExtensionTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Security.Claims; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using Microsoft.Extensions.Caching.Memory; @@ -62,7 +63,7 @@ namespace Squidex.Domain.Apps.Entities.Contents .AddInvariant(JsonValue.Array(referenceId1))); A.CallTo(() => contentQuery.QueryAsync( - A.That.Matches(x => x.App.Id == appId.Id && x.User == user), A.That.HasIds(referenceId1))) + A.That.Matches(x => x.App.Id == appId.Id && x.User == user), A.That.HasIds(referenceId1), A._)) .Returns(ResultList.CreateFrom(1, reference1)); var vars = new ScriptVars { Data = data, AppId = appId.Id, User = user }; @@ -100,7 +101,7 @@ namespace Squidex.Domain.Apps.Entities.Contents .AddInvariant(JsonValue.Array(referenceId1, referenceId2))); A.CallTo(() => contentQuery.QueryAsync( - A.That.Matches(x => x.App.Id == appId.Id && x.User == user), A.That.HasIds(referenceId1, referenceId2))) + A.That.Matches(x => x.App.Id == appId.Id && x.User == user), A.That.HasIds(referenceId1, referenceId2), A._)) .Returns(ResultList.CreateFrom(2, reference1, reference2)); var vars = new ScriptVars { Data = data, AppId = appId.Id, User = user }; diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Queries/RuleEnricherTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Queries/RuleEnricherTests.cs index 5bd8067a5..2842e830c 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Queries/RuleEnricherTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Rules/Queries/RuleEnricherTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System.Collections.Generic; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using NodaTime; @@ -64,7 +65,7 @@ namespace Squidex.Domain.Apps.Entities.Rules.Queries LastExecuted = SystemClock.Instance.GetCurrentInstant() }; - A.CallTo(() => ruleEventRepository.QueryStatisticsByAppAsync(appId.Id)) + A.CallTo(() => ruleEventRepository.QueryStatisticsByAppAsync(appId.Id, A._)) .Returns(new List { stats }); await sut.EnrichAsync(source, requestContext); diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemasSearchSourceTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemasSearchSourceTests.cs index ab8b3c311..222834984 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemasSearchSourceTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Schemas/SchemasSearchSourceTests.cs @@ -47,7 +47,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas A.CallTo(() => urlGenerator.SchemaUI(appId, schema1.NamedId())) .Returns("schemaA1-url"); - var result = await sut.SearchAsync("schema", ctx); + var result = await sut.SearchAsync("schema", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -69,7 +69,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas A.CallTo(() => urlGenerator.SchemaUI(appId, schema1.NamedId())) .Returns("schemaA1-url"); - var result = await sut.SearchAsync("schema", ctx); + var result = await sut.SearchAsync("schema", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -99,7 +99,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas A.CallTo(() => urlGenerator.ContentsUI(appId, schema2.NamedId())) .Returns("schemaA2-contents-url"); - var result = await sut.SearchAsync("schemaA", ctx); + var result = await sut.SearchAsync("schemaA", ctx, default); result.Should().BeEquivalentTo( new SearchResults() @@ -126,7 +126,7 @@ namespace Squidex.Domain.Apps.Entities.Schemas A.CallTo(() => urlGenerator.ContentUI(appId, schema1.NamedId(), schema1.Id)) .Returns("schemaA1-content-url"); - var result = await sut.SearchAsync("schemaA", ctx); + var result = await sut.SearchAsync("schemaA", ctx, default); result.Should().BeEquivalentTo( new SearchResults() diff --git a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Search/SearchManagerTests.cs b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Search/SearchManagerTests.cs index 3252a0e12..4d357060d 100644 --- a/backend/tests/Squidex.Domain.Apps.Entities.Tests/Search/SearchManagerTests.cs +++ b/backend/tests/Squidex.Domain.Apps.Entities.Tests/Search/SearchManagerTests.cs @@ -6,6 +6,7 @@ // ========================================================================== using System; +using System.Threading; using System.Threading.Tasks; using FakeItEasy; using FluentAssertions; @@ -36,10 +37,10 @@ namespace Squidex.Domain.Apps.Entities.Search Assert.Empty(result); - A.CallTo(() => source1.SearchAsync(A._, A._)) + A.CallTo(() => source1.SearchAsync(A._, A._, A._)) .MustNotHaveHappened(); - A.CallTo(() => source2.SearchAsync(A._, A._)) + A.CallTo(() => source2.SearchAsync(A._, A._, A._)) .MustNotHaveHappened(); } @@ -50,10 +51,10 @@ namespace Squidex.Domain.Apps.Entities.Search Assert.Empty(result); - A.CallTo(() => source1.SearchAsync(A._, A._)) + A.CallTo(() => source1.SearchAsync(A._, A._, A._)) .MustNotHaveHappened(); - A.CallTo(() => source2.SearchAsync(A._, A._)) + A.CallTo(() => source2.SearchAsync(A._, A._, A._)) .MustNotHaveHappened(); } @@ -65,10 +66,10 @@ namespace Squidex.Domain.Apps.Entities.Search var query = "a query"; - A.CallTo(() => source1.SearchAsync(query, requestContext)) + A.CallTo(() => source1.SearchAsync(query, requestContext, A._)) .Returns(result1); - A.CallTo(() => source2.SearchAsync(query, requestContext)) + A.CallTo(() => source2.SearchAsync(query, requestContext, A._)) .Returns(result2); var result = await sut.SearchAsync(query, requestContext); @@ -86,10 +87,10 @@ namespace Squidex.Domain.Apps.Entities.Search var query = "a query"; - A.CallTo(() => source1.SearchAsync(query, requestContext)) + A.CallTo(() => source1.SearchAsync(query, requestContext, A._)) .Throws(new InvalidOperationException()); - A.CallTo(() => source2.SearchAsync(query, requestContext)) + A.CallTo(() => source2.SearchAsync(query, requestContext, A._)) .Returns(result2); var result = await sut.SearchAsync(query, requestContext);