Browse Source

Closes #121

pull/131/head
Sebastian Stehle 9 years ago
parent
commit
fde6b44287
  1. 8
      src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs
  2. 2
      src/Squidex.Domain.Apps.Read/Webhooks/Repositories/IWebhookRepository.cs
  3. 2
      src/Squidex.Domain.Apps.Read/Webhooks/WebhookEnqueuer.cs
  4. 2
      tests/Squidex.Domain.Apps.Read.Tests/Webhooks/WebhookEnqueuerTests.cs

8
src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs

@ -8,6 +8,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Bson; using MongoDB.Bson;
@ -44,6 +45,13 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Webhooks
} }
public async Task<IReadOnlyList<IWebhookEntity>> QueryByAppAsync(Guid appId) public async Task<IReadOnlyList<IWebhookEntity>> QueryByAppAsync(Guid appId)
{
var entities = await Collection.Find(x => x.AppId == appId).ToListAsync();
return entities.OfType<IWebhookEntity>().ToList();
}
public async Task<IReadOnlyList<IWebhookEntity>> QueryCachedByAppAsync(Guid appId)
{ {
await EnsureWebooksLoadedAsync(); await EnsureWebooksLoadedAsync();

2
src/Squidex.Domain.Apps.Read/Webhooks/Repositories/IWebhookRepository.cs

@ -17,5 +17,7 @@ namespace Squidex.Domain.Apps.Read.Webhooks.Repositories
Task TraceSentAsync(Guid webhookId, WebhookResult result, TimeSpan elapsed); Task TraceSentAsync(Guid webhookId, WebhookResult result, TimeSpan elapsed);
Task<IReadOnlyList<IWebhookEntity>> QueryByAppAsync(Guid appId); Task<IReadOnlyList<IWebhookEntity>> QueryByAppAsync(Guid appId);
Task<IReadOnlyList<IWebhookEntity>> QueryCachedByAppAsync(Guid appId);
} }
} }

2
src/Squidex.Domain.Apps.Read/Webhooks/WebhookEnqueuer.cs

@ -75,7 +75,7 @@ namespace Squidex.Domain.Apps.Read.Webhooks
{ {
var eventType = typeNameRegistry.GetName(@event.Payload.GetType()); var eventType = typeNameRegistry.GetName(@event.Payload.GetType());
var webhooks = await webhookRepository.QueryByAppAsync(contentEvent.AppId.Id); var webhooks = await webhookRepository.QueryCachedByAppAsync(contentEvent.AppId.Id);
var matchingWebhooks = webhooks.Where(w => w.Schemas.Any(s => Matchs(s, contentEvent))).ToList(); var matchingWebhooks = webhooks.Where(w => w.Schemas.Any(s => Matchs(s, contentEvent))).ToList();

2
tests/Squidex.Domain.Apps.Read.Tests/Webhooks/WebhookEnqueuerTests.cs

@ -71,7 +71,7 @@ namespace Squidex.Domain.Apps.Read.Webhooks
var webhook1 = CreateWebhook(1); var webhook1 = CreateWebhook(1);
var webhook2 = CreateWebhook(2); var webhook2 = CreateWebhook(2);
A.CallTo(() => webhookRepository.QueryByAppAsync(appId.Id)) A.CallTo(() => webhookRepository.QueryCachedByAppAsync(appId.Id))
.Returns(new List<IWebhookEntity> { webhook1, webhook2 }); .Returns(new List<IWebhookEntity> { webhook1, webhook2 });
await sut.On(@event); await sut.On(@event);

Loading…
Cancel
Save