mirror of https://github.com/Squidex/squidex.git
Browse Source
* Update Oidc client. * Improve the queries and tests * Another performance improvement. * Fix tests * Unify code. * Fix readme.pull/983/head
committed by
GitHub
54 changed files with 498 additions and 443 deletions
@ -0,0 +1,43 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using MongoDB.Bson; |
|||
using MongoDB.Driver; |
|||
|
|||
#pragma warning disable CA1822 // Mark members as static
|
|||
|
|||
namespace Squidex.Infrastructure.MongoDb; |
|||
|
|||
public sealed class ProfilerCollection |
|||
{ |
|||
private readonly IMongoCollection<ProfilerDocument> collection; |
|||
|
|||
public string CollectionName => "system.profile"; |
|||
|
|||
public ProfilerCollection(IMongoDatabase database) |
|||
{ |
|||
collection = database.GetCollection<ProfilerDocument>(CollectionName); |
|||
} |
|||
|
|||
public async Task<IReadOnlyList<ProfilerDocument>> GetQueriesAsync(string collectionName, |
|||
CancellationToken ct = default) |
|||
{ |
|||
var ns = $"{collection.Database.DatabaseNamespace.DatabaseName}.{collectionName}"; |
|||
|
|||
return await collection.Find(x => x.Operation == "query" && x.Namespace == ns).ToListAsync(ct); |
|||
} |
|||
|
|||
public async Task ClearAsync( |
|||
CancellationToken ct = default) |
|||
{ |
|||
var database = collection.Database; |
|||
|
|||
await database.RunCommandAsync<BsonDocument>("{ profile : 0 }", cancellationToken: ct); |
|||
await database.DropCollectionAsync(ProfilerDocument.CollectionName, ct); |
|||
await database.RunCommandAsync<BsonDocument>("{ profile : 2 }", cancellationToken: ct); |
|||
} |
|||
} |
|||
@ -0,0 +1,35 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
using MongoDB.Bson; |
|||
using MongoDB.Bson.Serialization.Attributes; |
|||
|
|||
namespace Squidex.Infrastructure.MongoDb; |
|||
|
|||
[BsonIgnoreExtraElements] |
|||
public sealed class ProfilerDocument |
|||
{ |
|||
public const string CollectionName = "system.profile"; |
|||
|
|||
[BsonElement("op")] |
|||
public string Operation { get; set; } |
|||
|
|||
[BsonElement("ns")] |
|||
public string Namespace { get; set; } |
|||
|
|||
[BsonElement("nreturned")] |
|||
public int NumDocuments { get; set; } |
|||
|
|||
[BsonElement("keysExamined")] |
|||
public int KeysExamined { get; set; } |
|||
|
|||
[BsonElement("docsExamined")] |
|||
public int DocsExamined { get; set; } |
|||
|
|||
[BsonElement("planSummary")] |
|||
public string PlanSummary { get; set; } |
|||
} |
|||
@ -1,22 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
#pragma warning disable MA0048 // File name must match type name
|
|||
|
|||
namespace Squidex.Infrastructure.EventSourcing; |
|||
|
|||
public interface IEventNotifier |
|||
{ |
|||
void NotifyEventsStored(string streamName); |
|||
} |
|||
|
|||
public sealed class NoopEventNotifier : IEventNotifier |
|||
{ |
|||
public void NotifyEventsStored(string streamName) |
|||
{ |
|||
} |
|||
} |
|||
@ -0,0 +1,67 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
#pragma warning disable SA1300 // Element should begin with upper-case letter
|
|||
#pragma warning disable MA0048 // File name must match type name
|
|||
|
|||
using Squidex.Infrastructure.MongoDb; |
|||
|
|||
namespace Squidex.Infrastructure.EventSourcing; |
|||
|
|||
public abstract class MongoEventStoreTests : EventStoreTests<MongoEventStore>, IAsyncLifetime |
|||
{ |
|||
private ProfilerCollection profiler; |
|||
|
|||
public MongoEventStoreFixture _ { get; } |
|||
|
|||
protected MongoEventStoreTests(MongoEventStoreFixture fixture) |
|||
{ |
|||
_ = fixture; |
|||
} |
|||
|
|||
public override MongoEventStore CreateStore() |
|||
{ |
|||
return _.EventStore; |
|||
} |
|||
|
|||
public Task InitializeAsync() |
|||
{ |
|||
profiler = new ProfilerCollection(_.Database); |
|||
|
|||
return profiler.ClearAsync(); |
|||
} |
|||
|
|||
public async Task DisposeAsync() |
|||
{ |
|||
var queries = await profiler.GetQueriesAsync("Events2"); |
|||
|
|||
Assert.All(queries, query => |
|||
{ |
|||
Assert.Equal(query.NumDocuments, query.DocsExamined); |
|||
Assert.True(query.KeysExamined >= query.NumDocuments); |
|||
Assert.True(query.KeysExamined <= query.NumDocuments * 2); |
|||
}); |
|||
} |
|||
} |
|||
|
|||
[Trait("Category", "Dependencies")] |
|||
public sealed class MongoEventStoreTests_Direct : MongoEventStoreTests, IClassFixture<MongoEventStoreFixture_Direct> |
|||
{ |
|||
public MongoEventStoreTests_Direct(MongoEventStoreFixture_Direct fixture) |
|||
: base(fixture) |
|||
{ |
|||
} |
|||
} |
|||
|
|||
[Trait("Category", "Dependencies")] |
|||
public sealed class MongoEventStoreTests_Replica : MongoEventStoreTests, IClassFixture<MongoEventStoreFixture_Replica> |
|||
{ |
|||
public MongoEventStoreTests_Replica(MongoEventStoreFixture_Replica fixture) |
|||
: base(fixture) |
|||
{ |
|||
} |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
#pragma warning disable SA1300 // Element should begin with upper-case letter
|
|||
|
|||
namespace Squidex.Infrastructure.EventSourcing; |
|||
|
|||
[Trait("Category", "Dependencies")] |
|||
public class MongoEventStoreTests_Direct : EventStoreTests<MongoEventStore>, IClassFixture<MongoEventStoreDirectFixture> |
|||
{ |
|||
public MongoEventStoreFixture _ { get; } |
|||
|
|||
public MongoEventStoreTests_Direct(MongoEventStoreDirectFixture fixture) |
|||
{ |
|||
_ = fixture; |
|||
} |
|||
|
|||
public override MongoEventStore CreateStore() |
|||
{ |
|||
return _.EventStore; |
|||
} |
|||
} |
|||
@ -1,26 +0,0 @@ |
|||
// ==========================================================================
|
|||
// Squidex Headless CMS
|
|||
// ==========================================================================
|
|||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|||
// All rights reserved. Licensed under the MIT license.
|
|||
// ==========================================================================
|
|||
|
|||
#pragma warning disable SA1300 // Element should begin with upper-case letter
|
|||
|
|||
namespace Squidex.Infrastructure.EventSourcing; |
|||
|
|||
[Trait("Category", "Dependencies")] |
|||
public class MongoEventStoreTests_ReplicaSet : EventStoreTests<MongoEventStore>, IClassFixture<MongoEventStoreReplicaSetFixture> |
|||
{ |
|||
public MongoEventStoreFixture _ { get; } |
|||
|
|||
public MongoEventStoreTests_ReplicaSet(MongoEventStoreReplicaSetFixture fixture) |
|||
{ |
|||
_ = fixture; |
|||
} |
|||
|
|||
public override MongoEventStore CreateStore() |
|||
{ |
|||
return _.EventStore; |
|||
} |
|||
} |
|||
Loading…
Reference in new issue