From a8d16f392d0fdb352241e7c8617fec7efd9ab36d Mon Sep 17 00:00:00 2001 From: Sebastian Date: Sat, 20 Jun 2020 16:28:55 +0200 Subject: [PATCH] Async improvements. --- .../Actions/Algolia/AlgoliaActionHandler.cs | 2 +- .../Actions/AzureQueue/AzureQueueActionHandler.cs | 2 +- .../extensions/Squidex.Extensions/Actions/ClientPool.cs | 5 ----- .../Actions/ElasticSearch/ElasticSearchActionHandler.cs | 2 +- .../Squidex.Domain.Apps.Core.Model/Comments/Comment.cs | 4 ++++ .../Infrastructure/MongoPersistedGrantStore.cs | 8 ++++---- .../EventSourcing/GetEventStoreSubscription.cs | 4 ++-- .../Log/Store/BackgroundRequestLogStore.cs | 1 + 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/backend/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaActionHandler.cs b/backend/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaActionHandler.cs index aeaf40fbb..003bc485f 100644 --- a/backend/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaActionHandler.cs +++ b/backend/extensions/Squidex.Extensions/Actions/Algolia/AlgoliaActionHandler.cs @@ -96,7 +96,7 @@ namespace Squidex.Extensions.Actions.Algolia return Result.Ignored(); } - var index = clients.GetClient((job.AppId, job.ApiKey, job.IndexName)); + var index = await clients.GetClientAsync((job.AppId, job.ApiKey, job.IndexName)); try { diff --git a/backend/extensions/Squidex.Extensions/Actions/AzureQueue/AzureQueueActionHandler.cs b/backend/extensions/Squidex.Extensions/Actions/AzureQueue/AzureQueueActionHandler.cs index 8339a74de..77773be39 100644 --- a/backend/extensions/Squidex.Extensions/Actions/AzureQueue/AzureQueueActionHandler.cs +++ b/backend/extensions/Squidex.Extensions/Actions/AzureQueue/AzureQueueActionHandler.cs @@ -49,7 +49,7 @@ namespace Squidex.Extensions.Actions.AzureQueue protected override async Task ExecuteJobAsync(AzureQueueJob job, CancellationToken ct = default) { - var queue = clients.GetClient((job.QueueConnectionString, job.QueueName)); + var queue = await clients.GetClientAsync((job.QueueConnectionString, job.QueueName)); await queue.AddMessageAsync(new CloudQueueMessage(job.MessageBodyV2), null, null, null, null, ct); diff --git a/backend/extensions/Squidex.Extensions/Actions/ClientPool.cs b/backend/extensions/Squidex.Extensions/Actions/ClientPool.cs index c63b7c799..b65ad0fe9 100644 --- a/backend/extensions/Squidex.Extensions/Actions/ClientPool.cs +++ b/backend/extensions/Squidex.Extensions/Actions/ClientPool.cs @@ -30,11 +30,6 @@ namespace Squidex.Extensions.Actions this.factory = factory; } - public TClient GetClient(TKey key) - { - return GetClientAsync(key).Result; - } - public async Task GetClientAsync(TKey key) { if (!memoryCache.TryGetValue(key, out var client)) diff --git a/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs b/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs index 19e367783..a1c0e6363 100644 --- a/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs +++ b/backend/extensions/Squidex.Extensions/Actions/ElasticSearch/ElasticSearchActionHandler.cs @@ -80,7 +80,7 @@ namespace Squidex.Extensions.Actions.ElasticSearch return Result.Ignored(); } - var client = clients.GetClient((new Uri(job.ServerHost, UriKind.Absolute), job.ServerUser, job.ServerPassword)); + var client = await clients.GetClientAsync((new Uri(job.ServerHost, UriKind.Absolute), job.ServerUser, job.ServerPassword)); try { diff --git a/backend/src/Squidex.Domain.Apps.Core.Model/Comments/Comment.cs b/backend/src/Squidex.Domain.Apps.Core.Model/Comments/Comment.cs index 915edb8e8..238ab6f4d 100644 --- a/backend/src/Squidex.Domain.Apps.Core.Model/Comments/Comment.cs +++ b/backend/src/Squidex.Domain.Apps.Core.Model/Comments/Comment.cs @@ -30,9 +30,13 @@ namespace Squidex.Domain.Apps.Core.Comments Guard.NotNull(text, nameof(text)); Id = id; + Text = text; + Time = time; + User = user; + Url = url; } } diff --git a/backend/src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs b/backend/src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs index 8c9dbd6e9..928d6a732 100644 --- a/backend/src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs +++ b/backend/src/Squidex.Domain.Users.MongoDb/Infrastructure/MongoPersistedGrantStore.cs @@ -47,14 +47,14 @@ namespace Squidex.Domain.Users.MongoDb.Infrastructure }, ct); } - public Task StoreAsync(PersistedGrant grant) + public async Task> GetAllAsync(string subjectId) { - return Collection.ReplaceOneAsync(x => x.Key == grant.Key, grant, UpsertReplace); + return await Collection.Find(x => x.SubjectId == subjectId).ToListAsync(); } - public Task> GetAllAsync(string subjectId) + public Task StoreAsync(PersistedGrant grant) { - return Collection.Find(x => x.SubjectId == subjectId).ToListAsync().ContinueWith(x => (IEnumerable)x.Result); + return Collection.ReplaceOneAsync(x => x.Key == grant.Key, grant, UpsertReplace); } public Task GetAsync(string key) diff --git a/backend/src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStoreSubscription.cs b/backend/src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStoreSubscription.cs index 08f317743..90d25eec3 100644 --- a/backend/src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStoreSubscription.cs +++ b/backend/src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStoreSubscription.cs @@ -59,11 +59,11 @@ namespace Squidex.Infrastructure.EventSourcing var settings = CatchUpSubscriptionSettings.Default; return connection.SubscribeToStreamFrom(streamName, position, settings, - (s, e) => + async (s, e) => { var storedEvent = Formatter.Read(e, prefix, serializer); - subscriber.OnEventAsync(this, storedEvent).Wait(); + await subscriber.OnEventAsync(this, storedEvent); }, null, (s, reason, ex) => { diff --git a/backend/src/Squidex.Infrastructure/Log/Store/BackgroundRequestLogStore.cs b/backend/src/Squidex.Infrastructure/Log/Store/BackgroundRequestLogStore.cs index 8343209e8..c19fdd047 100644 --- a/backend/src/Squidex.Infrastructure/Log/Store/BackgroundRequestLogStore.cs +++ b/backend/src/Squidex.Infrastructure/Log/Store/BackgroundRequestLogStore.cs @@ -29,6 +29,7 @@ namespace Squidex.Infrastructure.Log.Store Guard.NotNull(log, nameof(log)); this.logRepository = logRepository; + this.log = log; timer = new CompletionTimer(Intervall, ct => TrackAsync(), Intervall);