diff --git a/src/Squidex.Domain.Apps.Entities/Contents/Text/GrainTextIndexer.cs b/src/Squidex.Domain.Apps.Entities/Contents/Text/GrainTextIndexer.cs index 19c8e455fd..5f349f6518 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/Text/GrainTextIndexer.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/Text/GrainTextIndexer.cs @@ -57,11 +57,6 @@ public async Task On(Envelope @event) { var index = grainFactory.GetGrain(contentEvent.SchemaId.Id); - if (index == null) - { - throw new InvalidOperationException("Cannot create reference to grain."); - } - var id = contentEvent.ContentId; switch (@event.Payload) @@ -70,13 +65,13 @@ public async Task On(Envelope @event) await index.DeleteAsync(id); break; case ContentCreated contentCreated: - await index.IndexAsync(id, Data(contentCreated.Data), true); + await index.IndexAsync(Data(id, contentCreated.Data, true)); break; case ContentUpdateProposed contentUpdateProposed: - await index.IndexAsync(id, Data(contentUpdateProposed.Data), true); + await index.IndexAsync(Data(id, contentUpdateProposed.Data, true)); break; case ContentUpdated contentUpdated: - await index.IndexAsync(id, Data(contentUpdated.Data), false); + await index.IndexAsync(Data(id, contentUpdated.Data, false)); break; case ContentChangesDiscarded _: await index.CopyAsync(id, false); @@ -89,9 +84,9 @@ public async Task On(Envelope @event) } } - private static J Data(NamedContentData data) + private static J Data(Guid contentId, NamedContentData data, bool onlySelf) { - return new IndexData { Data = data }; + return new Update { Id = contentId, Data = data, OnlyDraft = onlySelf }; } public async Task> SearchAsync(string queryText, IAppEntity app, Guid schemaId, Scope scope = Scope.Published) diff --git a/src/Squidex.Domain.Apps.Entities/Contents/Text/ITextIndexerGrain.cs b/src/Squidex.Domain.Apps.Entities/Contents/Text/ITextIndexerGrain.cs index 6f9b71b492..486591d6d1 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/Text/ITextIndexerGrain.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/Text/ITextIndexerGrain.cs @@ -15,11 +15,11 @@ namespace Squidex.Domain.Apps.Entities.Contents.Text { public interface ITextIndexerGrain : IGrainWithGuidKey { - Task DeleteAsync(Guid id); + Task DeleteAsync(Guid id); - Task IndexAsync(Guid id, J data, bool onlyDraft); + Task CopyAsync(Guid id, bool fromDraft); - Task CopyAsync(Guid id, bool fromDraft); + Task IndexAsync(J update); Task> SearchAsync(string queryText, SearchContext context); } diff --git a/src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexerGrain.cs b/src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexerGrain.cs index 134a048447..926f8e5102 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexerGrain.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/Text/TextIndexerGrain.cs @@ -81,29 +81,34 @@ protected override async Task OnActivateAsync(Guid key) } } - public Task DeleteAsync(Guid id) + public Task IndexAsync(J update) { - var content = new TextIndexContent(indexWriter, indexState, id); + return IndexInternalAsync(update); + } - content.Delete(); + private Task IndexInternalAsync(Update update) + { + var content = new TextIndexContent(indexWriter, indexState, update.Id); + + content.Index(update.Data, update.OnlyDraft); return TryFlushAsync(); } - public Task IndexAsync(Guid id, J data, bool onlyDraft) + public Task CopyAsync(Guid id, bool fromDraft) { var content = new TextIndexContent(indexWriter, indexState, id); - content.Index(data.Value.Data, onlyDraft); + content.Copy(fromDraft); return TryFlushAsync(); } - public Task CopyAsync(Guid id, bool fromDraft) + public Task DeleteAsync(Guid id) { var content = new TextIndexContent(indexWriter, indexState, id); - content.Copy(fromDraft); + content.Delete(); return TryFlushAsync(); } @@ -164,7 +169,7 @@ private Query BuildQuery(string query, SearchContext context) } } - private async Task TryFlushAsync() + private async Task TryFlushAsync() { timer?.Dispose(); @@ -173,6 +178,8 @@ private async Task TryFlushAsync() if (updates >= MaxUpdates) { await FlushAsync(); + + return true; } else { @@ -184,9 +191,11 @@ private async Task TryFlushAsync() } catch (InvalidOperationException) { - return; + return false; } } + + return false; } public async Task FlushAsync() diff --git a/src/Squidex.Domain.Apps.Entities/Contents/Text/IndexData.cs b/src/Squidex.Domain.Apps.Entities/Contents/Text/Update.cs similarity index 80% rename from src/Squidex.Domain.Apps.Entities/Contents/Text/IndexData.cs rename to src/Squidex.Domain.Apps.Entities/Contents/Text/Update.cs index 240cc0fda9..263ff50ad0 100644 --- a/src/Squidex.Domain.Apps.Entities/Contents/Text/IndexData.cs +++ b/src/Squidex.Domain.Apps.Entities/Contents/Text/Update.cs @@ -5,12 +5,17 @@ // All rights reserved. Licensed under the MIT license. // ========================================================================== +using System; using Squidex.Domain.Apps.Core.Contents; namespace Squidex.Domain.Apps.Entities.Contents.Text { - public sealed class IndexData + public sealed class Update { + public Guid Id { get; set; } + public NamedContentData Data { get; set; } + + public bool OnlyDraft { get; set; } } } diff --git a/src/Squidex/Config/Domain/SerializationInitializer.cs b/src/Squidex/Config/Domain/SerializationInitializer.cs index bdec8c549b..0254b318b5 100644 --- a/src/Squidex/Config/Domain/SerializationInitializer.cs +++ b/src/Squidex/Config/Domain/SerializationInitializer.cs @@ -12,30 +12,48 @@ using Squidex.Areas.Api.Controllers.Rules.Models; using Squidex.Domain.Apps.Core.HandleRules; using Squidex.Infrastructure; +using Squidex.Infrastructure.Json; using Squidex.Infrastructure.MongoDb; +using Squidex.Infrastructure.Orleans; using Squidex.Infrastructure.Tasks; namespace Squidex.Config.Domain { public sealed class SerializationInitializer : IInitializable { - private readonly JsonSerializer jsonSerializer; + private readonly JsonSerializer jsonNetSerializer; + private readonly IJsonSerializer jsonSerializer; private readonly RuleRegistry ruleRegistry; - public SerializationInitializer(JsonSerializer jsonSerializer, RuleRegistry ruleRegistry) + public SerializationInitializer(JsonSerializer jsonNetSerializer, IJsonSerializer jsonSerializer, RuleRegistry ruleRegistry) { + this.jsonNetSerializer = jsonNetSerializer; this.jsonSerializer = jsonSerializer; - this.ruleRegistry = ruleRegistry; } public Task InitializeAsync(CancellationToken ct = default) { - BsonJsonConvention.Register(jsonSerializer); + SetupBson(); + SetupOrleans(); + SetupActions(); + + return TaskHelper.Done; + } + private void SetupActions() + { RuleActionConverter.Mapping = ruleRegistry.Actions.ToDictionary(x => x.Key, x => x.Value.Type); + } - return TaskHelper.Done; + private void SetupBson() + { + BsonJsonConvention.Register(jsonNetSerializer); + } + + private void SetupOrleans() + { + J.DefaultSerializer = jsonSerializer; } } } diff --git a/src/Squidex/Config/Logging.cs b/src/Squidex/Config/Logging.cs index 201f2a4b44..76a2b22ea9 100644 --- a/src/Squidex/Config/Logging.cs +++ b/src/Squidex/Config/Logging.cs @@ -30,7 +30,7 @@ public static void AddFilter(this ILoggingBuilder builder) if (category.StartsWith("Orleans.Runtime.Scheduler", StringComparison.OrdinalIgnoreCase)) { - return level >= LogLevel.Error; + return level >= LogLevel.Warning; } if (category.StartsWith("Orleans.", StringComparison.OrdinalIgnoreCase)) @@ -45,7 +45,7 @@ public static void AddFilter(this ILoggingBuilder builder) if (category.StartsWith("Microsoft.AspNetCore.", StringComparison.OrdinalIgnoreCase)) { - return level > LogLevel.Information; + return level >= LogLevel.Warning; } #if LOG_ALL_IDENTITY_SERVER if (category.StartsWith("IdentityServer4.", StringComparison.OrdinalIgnoreCase)) diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/GrainTextIndexerTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/GrainTextIndexerTests.cs index e0d0e1f3bc..af936c2603 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/GrainTextIndexerTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/GrainTextIndexerTests.cs @@ -52,7 +52,7 @@ public async Task Should_call_grain_when_content_created() { await sut.On(E(new ContentCreated { Data = data })); - A.CallTo(() => grain.IndexAsync(contentId, A>.That.Matches(x => x.Value.Data == data), true)) + A.CallTo(() => grain.IndexAsync(A>.That.Matches(x => x.Value.Data == data && x.Value.Id == contentId && x.Value.OnlyDraft))) .MustHaveHappened(); } @@ -61,7 +61,7 @@ public async Task Should_call_grain_when_content_updated() { await sut.On(E(new ContentUpdated { Data = data })); - A.CallTo(() => grain.IndexAsync(contentId, A>.That.Matches(x => x.Value.Data == data), false)) + A.CallTo(() => grain.IndexAsync(A>.That.Matches(x => x.Value.Data == data && x.Value.Id == contentId && !x.Value.OnlyDraft))) .MustHaveHappened(); } @@ -70,7 +70,7 @@ public async Task Should_call_grain_when_content_change_proposed() { await sut.On(E(new ContentUpdateProposed { Data = data })); - A.CallTo(() => grain.IndexAsync(contentId, A>.That.Matches(x => x.Value.Data == data), true)) + A.CallTo(() => grain.IndexAsync(A>.That.Matches(x => x.Value.Data == data && x.Value.Id == contentId && x.Value.OnlyDraft))) .MustHaveHappened(); } diff --git a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/TextIndexerGrainTests.cs b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/TextIndexerGrainTests.cs index 1970a06636..7814cb6b96 100644 --- a/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/TextIndexerGrainTests.cs +++ b/tests/Squidex.Domain.Apps.Entities.Tests/Contents/Text/TextIndexerGrainTests.cs @@ -211,8 +211,8 @@ private async Task AddLocalizedContent() new ContentFieldData() .AddValue("en", "City and Surroundings und sonstiges")); - await sut.IndexAsync(ids1[0], new IndexData { Data = germanData }, true); - await sut.IndexAsync(ids2[0], new IndexData { Data = englishData }, true); + await sut.IndexAsync(new Update { Id = ids1[0], Data = germanData, OnlyDraft = true }); + await sut.IndexAsync(new Update { Id = ids2[0], Data = englishData, OnlyDraft = true }); } private async Task AddInvariantContent(string text1, string text2, bool onlyDraft = false) @@ -229,8 +229,8 @@ private async Task AddInvariantContent(string text1, string text2, bool onlyDraf new ContentFieldData() .AddValue("iv", text2)); - await sut.IndexAsync(ids1[0], new IndexData { Data = data1 }, onlyDraft); - await sut.IndexAsync(ids2[0], new IndexData { Data = data2 }, onlyDraft); + await sut.IndexAsync(new Update { Id = ids1[0], Data = data1, OnlyDraft = onlyDraft }); + await sut.IndexAsync(new Update { Id = ids2[0], Data = data2, OnlyDraft = onlyDraft }); } private async Task DeleteAsync(Guid id)