diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppEntity.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppEntity.cs index 35148eb7c..c44b2f5d9 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppEntity.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppEntity.cs @@ -41,6 +41,10 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps [BsonElement] public string MasterLanguage { get; set; } + [BsonRequired] + [BsonElement] + public List ContributorIds { get; set; } + [BsonRequired] [BsonElement] public List Languages { get; set; } = new List(); diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository.cs index cc5c93cd7..0b897fada 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository.cs @@ -29,9 +29,10 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps return "Projections_Apps"; } - protected override Task SetupCollectionAsync(IMongoCollection collection) + protected override async Task SetupCollectionAsync(IMongoCollection collection) { - return collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Name)); + await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Name)); + await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.ContributorIds)); } protected override MongoCollectionSettings CollectionSettings() @@ -42,7 +43,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps public async Task> QueryAllAsync(string subjectId) { var appEntities = - await Collection.Find(s => s.Contributors.ContainsKey(subjectId)) + await Collection.Find(s => s.ContributorIds.Contains(subjectId)) .ToListAsync(); return appEntities; diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository_EventHandling.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository_EventHandling.cs index e647e6d61..edf161961 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository_EventHandling.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository_EventHandling.cs @@ -6,6 +6,7 @@ // All rights reserved. // ========================================================================== +using System.Linq; using System.Threading.Tasks; using Squidex.Domain.Apps.Events.Apps; using Squidex.Domain.Apps.Read.MongoDb.Utils; @@ -41,14 +42,6 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps }); } - protected Task On(AppContributorRemoved @event, EnvelopeHeaders headers) - { - return Collection.UpdateAsync(@event, headers, a => - { - a.Contributors.Remove(@event.ContributorId); - }); - } - protected Task On(AppClientAttached @event, EnvelopeHeaders headers) { return Collection.UpdateAsync(@event, headers, a => @@ -114,6 +107,15 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps }); } + protected Task On(AppContributorRemoved @event, EnvelopeHeaders headers) + { + return Collection.UpdateAsync(@event, headers, a => + { + a.Contributors.Remove(@event.ContributorId); + a.ContributorIds = a.Contributors.Keys.ToList(); + }); + } + protected Task On(AppContributorAssigned @event, EnvelopeHeaders headers) { return Collection.UpdateAsync(@event, headers, a => @@ -121,6 +123,8 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps var contributor = a.Contributors.GetOrAddNew(@event.ContributorId); SimpleMapper.Map(@event, contributor); + + a.ContributorIds = a.Contributors.Keys.ToList(); }); } } diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Schemas/MongoSchemaRepository.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Schemas/MongoSchemaRepository.cs index 361056b7f..0a7d9459e 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Schemas/MongoSchemaRepository.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Schemas/MongoSchemaRepository.cs @@ -44,7 +44,9 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas protected override Task SetupCollectionAsync(IMongoCollection collection) { - return collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Name)); + return Task.WhenAll( + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Name)), + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId).Ascending(x => x.IsDeleted).Ascending(x => x.Name))); } public async Task> QueryAllAsync(Guid appId) @@ -61,7 +63,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas public async Task FindSchemaAsync(Guid appId, string name) { var schemaEntity = - await Collection.Find(s => s.Name == name && s.AppId == appId && !s.IsDeleted) + await Collection.Find(s => s.AppId == appId && !s.IsDeleted && s.Name == name) .FirstOrDefaultAsync(); schemaEntity?.DeserializeSchema(serializer); diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookEventRepository.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookEventRepository.cs index 5b1853c6f..db04caab3 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookEventRepository.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookEventRepository.cs @@ -37,11 +37,12 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Webhooks return "WebhookEvents"; } - protected override async Task SetupCollectionAsync(IMongoCollection collection) + protected override Task SetupCollectionAsync(IMongoCollection collection) { - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NextAttempt).Descending(x => x.IsSending)); - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId).Descending(x => x.Created)); - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Expires), new CreateIndexOptions { ExpireAfter = TimeSpan.Zero }); + return Task.WhenAll( + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NextAttempt).Descending(x => x.IsSending)), + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId).Descending(x => x.Created)), + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Expires), new CreateIndexOptions { ExpireAfter = TimeSpan.Zero })); } public Task QueryPendingAsync(Func callback, CancellationToken cancellationToken = default(CancellationToken)) diff --git a/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs b/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs index 9e9750e83..cacfc3725 100644 --- a/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs +++ b/src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs @@ -36,10 +36,11 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Webhooks return "Projections_SchemaWebhooks"; } - protected override async Task SetupCollectionAsync(IMongoCollection collection) + protected override Task SetupCollectionAsync(IMongoCollection collection) { - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId)); - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.SchemaIds)); + return Task.WhenAll( + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId)), + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.SchemaIds))); } public async Task> QueryByAppAsync(Guid appId) diff --git a/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs b/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs index 964e9a990..4565efd0c 100644 --- a/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs +++ b/src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs @@ -49,6 +49,7 @@ namespace Squidex.Domain.Users.MongoDb protected override Task SetupCollectionAsync(IMongoCollection collection) { return Task.WhenAll( + collection.Indexes.CreateOneAsync(Index.Ascending("Logins.LoginProvider").Ascending("Logins.ProviderKey")), collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NormalizedUserName), new CreateIndexOptions { Unique = true }), collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NormalizedEmail), new CreateIndexOptions { Unique = true })); } diff --git a/src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs b/src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs index a52e0a925..5ec8cfbce 100644 --- a/src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs +++ b/src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs @@ -48,10 +48,11 @@ namespace Squidex.Infrastructure.CQRS.Events return new MongoCollectionSettings { ReadPreference = ReadPreference.Primary, WriteConcern = WriteConcern.WMajority }; } - protected override async Task SetupCollectionAsync(IMongoCollection collection) + protected override Task SetupCollectionAsync(IMongoCollection collection) { - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Timestamp).Ascending(x => x.EventStream)); - await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.EventStream).Descending(x => x.EventStreamOffset), new CreateIndexOptions { Unique = true }); + return Task.WhenAll( + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Timestamp).Ascending(x => x.EventStream)), + collection.Indexes.CreateOneAsync(Index.Ascending(x => x.EventStream).Descending(x => x.EventStreamOffset), new CreateIndexOptions { Unique = true })); } public IEventSubscription CreateSubscription(string streamFilter = null, string position = null)