Browse Source

Merge branch 'master' into feature-history

pull/107/head
Sebastian Stehle 9 years ago
parent
commit
0eb21c601e
  1. 4
      src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppEntity.cs
  2. 7
      src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository.cs
  3. 20
      src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository_EventHandling.cs
  4. 6
      src/Squidex.Domain.Apps.Read.MongoDb/Schemas/MongoSchemaRepository.cs
  5. 9
      src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookEventRepository.cs
  6. 7
      src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookRepository.cs
  7. 1
      src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs
  8. 7
      src/Squidex.Infrastructure.MongoDb/CQRS/Events/MongoEventStore.cs

4
src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppEntity.cs

@ -41,6 +41,10 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps
[BsonElement] [BsonElement]
public string MasterLanguage { get; set; } public string MasterLanguage { get; set; }
[BsonRequired]
[BsonElement]
public List<string> ContributorIds { get; set; }
[BsonRequired] [BsonRequired]
[BsonElement] [BsonElement]
public List<MongoAppEntityLanguage> Languages { get; set; } = new List<MongoAppEntityLanguage>(); public List<MongoAppEntityLanguage> Languages { get; set; } = new List<MongoAppEntityLanguage>();

7
src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository.cs

@ -29,9 +29,10 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps
return "Projections_Apps"; return "Projections_Apps";
} }
protected override Task SetupCollectionAsync(IMongoCollection<MongoAppEntity> collection) protected override async Task SetupCollectionAsync(IMongoCollection<MongoAppEntity> 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() protected override MongoCollectionSettings CollectionSettings()
@ -42,7 +43,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps
public async Task<IReadOnlyList<IAppEntity>> QueryAllAsync(string subjectId) public async Task<IReadOnlyList<IAppEntity>> QueryAllAsync(string subjectId)
{ {
var appEntities = var appEntities =
await Collection.Find(s => s.Contributors.ContainsKey(subjectId)) await Collection.Find(s => s.ContributorIds.Contains(subjectId))
.ToListAsync(); .ToListAsync();
return appEntities; return appEntities;

20
src/Squidex.Domain.Apps.Read.MongoDb/Apps/MongoAppRepository_EventHandling.cs

@ -6,6 +6,7 @@
// All rights reserved. // All rights reserved.
// ========================================================================== // ==========================================================================
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Squidex.Domain.Apps.Events.Apps; using Squidex.Domain.Apps.Events.Apps;
using Squidex.Domain.Apps.Read.MongoDb.Utils; 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) protected Task On(AppClientAttached @event, EnvelopeHeaders headers)
{ {
return Collection.UpdateAsync(@event, headers, a => 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) protected Task On(AppContributorAssigned @event, EnvelopeHeaders headers)
{ {
return Collection.UpdateAsync(@event, headers, a => return Collection.UpdateAsync(@event, headers, a =>
@ -121,6 +123,8 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Apps
var contributor = a.Contributors.GetOrAddNew(@event.ContributorId); var contributor = a.Contributors.GetOrAddNew(@event.ContributorId);
SimpleMapper.Map(@event, contributor); SimpleMapper.Map(@event, contributor);
a.ContributorIds = a.Contributors.Keys.ToList();
}); });
} }
} }

6
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<MongoSchemaEntity> collection) protected override Task SetupCollectionAsync(IMongoCollection<MongoSchemaEntity> 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<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId) public async Task<IReadOnlyList<ISchemaEntity>> QueryAllAsync(Guid appId)
@ -61,7 +63,7 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Schemas
public async Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name) public async Task<ISchemaEntity> FindSchemaAsync(Guid appId, string name)
{ {
var schemaEntity = 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(); .FirstOrDefaultAsync();
schemaEntity?.DeserializeSchema(serializer); schemaEntity?.DeserializeSchema(serializer);

9
src/Squidex.Domain.Apps.Read.MongoDb/Webhooks/MongoWebhookEventRepository.cs

@ -37,11 +37,12 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Webhooks
return "WebhookEvents"; return "WebhookEvents";
} }
protected override async Task SetupCollectionAsync(IMongoCollection<MongoWebhookEventEntity> collection) protected override Task SetupCollectionAsync(IMongoCollection<MongoWebhookEventEntity> collection)
{ {
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NextAttempt).Descending(x => x.IsSending)); return Task.WhenAll(
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId).Descending(x => x.Created)); collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NextAttempt).Descending(x => x.IsSending)),
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Expires), new CreateIndexOptions { ExpireAfter = TimeSpan.Zero }); 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<IWebhookEventEntity, Task> callback, CancellationToken cancellationToken = default(CancellationToken)) public Task QueryPendingAsync(Func<IWebhookEventEntity, Task> callback, CancellationToken cancellationToken = default(CancellationToken))

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

@ -36,10 +36,11 @@ namespace Squidex.Domain.Apps.Read.MongoDb.Webhooks
return "Projections_SchemaWebhooks"; return "Projections_SchemaWebhooks";
} }
protected override async Task SetupCollectionAsync(IMongoCollection<MongoWebhookEntity> collection) protected override Task SetupCollectionAsync(IMongoCollection<MongoWebhookEntity> collection)
{ {
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId)); return Task.WhenAll(
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.SchemaIds)); collection.Indexes.CreateOneAsync(Index.Ascending(x => x.AppId)),
collection.Indexes.CreateOneAsync(Index.Ascending(x => x.SchemaIds)));
} }
public async Task<IReadOnlyList<IWebhookEntity>> QueryByAppAsync(Guid appId) public async Task<IReadOnlyList<IWebhookEntity>> QueryByAppAsync(Guid appId)

1
src/Squidex.Domain.Users.MongoDb/MongoUserStore.cs

@ -49,6 +49,7 @@ namespace Squidex.Domain.Users.MongoDb
protected override Task SetupCollectionAsync(IMongoCollection<MongoUser> collection) protected override Task SetupCollectionAsync(IMongoCollection<MongoUser> collection)
{ {
return Task.WhenAll( 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.NormalizedUserName), new CreateIndexOptions { Unique = true }),
collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NormalizedEmail), new CreateIndexOptions { Unique = true })); collection.Indexes.CreateOneAsync(Index.Ascending(x => x.NormalizedEmail), new CreateIndexOptions { Unique = true }));
} }

7
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 }; return new MongoCollectionSettings { ReadPreference = ReadPreference.Primary, WriteConcern = WriteConcern.WMajority };
} }
protected override async Task SetupCollectionAsync(IMongoCollection<MongoEventCommit> collection) protected override Task SetupCollectionAsync(IMongoCollection<MongoEventCommit> collection)
{ {
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.Timestamp).Ascending(x => x.EventStream)); return Task.WhenAll(
await collection.Indexes.CreateOneAsync(Index.Ascending(x => x.EventStream).Descending(x => x.EventStreamOffset), new CreateIndexOptions { Unique = true }); 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) public IEventSubscription CreateSubscription(string streamFilter = null, string position = null)

Loading…
Cancel
Save