Browse Source

Minor performance fix

pull/65/merge
Sebastian Stehle 9 years ago
parent
commit
c8bb256e86
  1. 32
      src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs

32
src/Squidex.Domain.Apps.Read.MongoDb/Contents/MongoContentRepository_EventHandling.cs

@ -9,9 +9,9 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using Squidex.Domain.Apps.Events.Apps;
using Squidex.Domain.Apps.Events.Assets; using Squidex.Domain.Apps.Events.Assets;
using Squidex.Domain.Apps.Events.Contents; using Squidex.Domain.Apps.Events.Contents;
using Squidex.Domain.Apps.Events.Schemas;
using Squidex.Domain.Apps.Read.MongoDb.Utils; using Squidex.Domain.Apps.Read.MongoDb.Utils;
using Squidex.Infrastructure.CQRS.Events; using Squidex.Infrastructure.CQRS.Events;
using Squidex.Infrastructure.Dispatching; using Squidex.Infrastructure.Dispatching;
@ -31,7 +31,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
public string EventsFilter public string EventsFilter
{ {
get { return "^(content-)|(schema-)|(asset-)"; } get { return "^(content-)|(app-)|(asset-)"; }
} }
public async Task ClearAsync() public async Task ClearAsync()
@ -58,7 +58,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
return this.DispatchActionAsync(@event.Payload, @event.Headers); return this.DispatchActionAsync(@event.Payload, @event.Headers);
} }
protected Task On(SchemaCreated @event, EnvelopeHeaders headers) protected Task On(AppCreated @event, EnvelopeHeaders headers)
{ {
return ForAppIdAsync(@event.AppId.Id, async collection => return ForAppIdAsync(@event.AppId.Id, async collection =>
{ {
@ -116,18 +116,6 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
}); });
} }
protected Task On(AssetDeleted @event, EnvelopeHeaders headers)
{
return ForAppIdAsync(@event.AppId.Id, collection =>
{
return collection.UpdateManyAsync(
Filter.And(
Filter.AnyEq(x => x.ReferencedIds, @event.AssetId),
Filter.AnyNe(x => x.ReferencedIdsDeleted, @event.AssetId)),
Update.AddToSet(x => x.ReferencedIdsDeleted, @event.AssetId));
});
}
protected Task On(ContentDeleted @event, EnvelopeHeaders headers) protected Task On(ContentDeleted @event, EnvelopeHeaders headers)
{ {
return ForAppIdAsync(@event.AppId.Id, async collection => return ForAppIdAsync(@event.AppId.Id, async collection =>
@ -141,7 +129,19 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Contents
await collection.DeleteOneAsync(x => x.Id == headers.AggregateId()); await collection.DeleteOneAsync(x => x.Id == headers.AggregateId());
}); });
} }
protected Task On(AssetDeleted @event, EnvelopeHeaders headers)
{
return ForAppIdAsync(@event.AppId.Id, collection =>
{
return collection.UpdateManyAsync(
Filter.And(
Filter.AnyEq(x => x.ReferencedIds, @event.AssetId),
Filter.AnyNe(x => x.ReferencedIdsDeleted, @event.AssetId)),
Update.AddToSet(x => x.ReferencedIdsDeleted, @event.AssetId));
});
}
private Task ForAppIdAsync(Guid appId, Func<IMongoCollection<MongoContentEntity>, Task> action) private Task ForAppIdAsync(Guid appId, Func<IMongoCollection<MongoContentEntity>, Task> action)
{ {
var collection = GetCollection(appId); var collection = GetCollection(appId);

Loading…
Cancel
Save