Browse Source

More profiling.

pull/289/head
Sebastian 8 years ago
parent
commit
783e7b7385
  1. 10
      src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs
  2. 7
      src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository_SnapshotStore.cs
  3. 42
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs
  4. 11
      src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs
  5. 16
      src/Squidex.Domain.Apps.Entities/Contents/ContentQueryService.cs
  6. 4
      src/Squidex.Domain.Apps.Entities/Contents/ContentVersionLoader.cs
  7. 13
      src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStore.cs
  8. 11
      src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore_Reader.cs
  9. 4
      src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore_Writer.cs
  10. 16
      src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs

10
src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository.cs

@ -15,6 +15,7 @@ using Squidex.Domain.Apps.Entities.Assets.Edm;
using Squidex.Domain.Apps.Entities.Assets.Repositories; using Squidex.Domain.Apps.Entities.Assets.Repositories;
using Squidex.Domain.Apps.Entities.MongoDb.Assets.Visitors; using Squidex.Domain.Apps.Entities.MongoDb.Assets.Visitors;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.MongoDb; using Squidex.Infrastructure.MongoDb;
namespace Squidex.Domain.Apps.Entities.MongoDb.Assets namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
@ -42,6 +43,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
} }
public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, string query = null) public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, string query = null)
{
using (Profiler.TraceMethod<MongoAssetRepository>("QueryAsyncByQuery"))
{ {
try try
{ {
@ -81,8 +84,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
} }
} }
} }
}
public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, HashSet<Guid> ids) public async Task<IResultList<IAssetEntity>> QueryAsync(Guid appId, HashSet<Guid> ids)
{
using (Profiler.TraceMethod<MongoAssetRepository>("QueryAsyncByIds"))
{ {
var find = Collection.Find(x => ids.Contains(x.Id)).SortByDescending(x => x.LastModified); var find = Collection.Find(x => ids.Contains(x.Id)).SortByDescending(x => x.LastModified);
@ -93,8 +99,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
return ResultList.Create(assetItems.Result.OfType<IAssetEntity>().ToList(), assetCount.Result); return ResultList.Create(assetItems.Result.OfType<IAssetEntity>().ToList(), assetCount.Result);
} }
}
public async Task<IAssetEntity> FindAssetAsync(Guid id) public async Task<IAssetEntity> FindAssetAsync(Guid id)
{
using (Profiler.TraceMethod<MongoAssetRepository>())
{ {
var assetEntity = var assetEntity =
await Collection.Find(x => x.Id == id) await Collection.Find(x => x.Id == id)
@ -103,4 +112,5 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
return assetEntity; return assetEntity;
} }
} }
}
} }

7
src/Squidex.Domain.Apps.Entities.MongoDb/Assets/MongoAssetRepository_SnapshotStore.cs

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using Squidex.Domain.Apps.Entities.Assets.State; using Squidex.Domain.Apps.Entities.Assets.State;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
@ -23,6 +24,8 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
} }
public async Task<(AssetState Value, long Version)> ReadAsync(Guid key) public async Task<(AssetState Value, long Version)> ReadAsync(Guid key)
{
using (Profiler.TraceMethod<MongoAssetRepository>())
{ {
var existing = var existing =
await Collection.Find(x => x.Id == key) await Collection.Find(x => x.Id == key)
@ -35,8 +38,11 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
return (null, EtagVersion.NotFound); return (null, EtagVersion.NotFound);
} }
}
public async Task WriteAsync(Guid key, AssetState value, long oldVersion, long newVersion) public async Task WriteAsync(Guid key, AssetState value, long oldVersion, long newVersion)
{
using (Profiler.TraceMethod<MongoAssetRepository>())
{ {
var entity = SimpleMapper.Map(value, new MongoAssetEntity()); var entity = SimpleMapper.Map(value, new MongoAssetEntity());
@ -46,4 +52,5 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Assets
await Collection.ReplaceOneAsync(x => x.Id == key && x.Version == oldVersion, entity, Upsert); await Collection.ReplaceOneAsync(x => x.Id == key && x.Version == oldVersion, entity, Upsert);
} }
} }
}
} }

42
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository.cs

@ -17,6 +17,7 @@ using Squidex.Domain.Apps.Entities.Contents;
using Squidex.Domain.Apps.Entities.Contents.Repositories; using Squidex.Domain.Apps.Entities.Contents.Repositories;
using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
namespace Squidex.Domain.Apps.Entities.MongoDb.Contents namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
@ -45,50 +46,65 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
contentsPublished.Initialize(); contentsPublished.Initialize();
} }
public Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchemaEntity schema, Status[] status, ODataUriParser odataQuery) public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchemaEntity schema, Status[] status, ODataUriParser odataQuery)
{
using (Profiler.TraceMethod<MongoContentRepository>("QueryAsyncByQuery"))
{ {
if (RequiresPublished(status)) if (RequiresPublished(status))
{ {
return contentsPublished.QueryAsync(app, schema, odataQuery); return await contentsPublished.QueryAsync(app, schema, odataQuery);
} }
else else
{ {
return contentsDraft.QueryAsync(app, schema, odataQuery, status, true); return await contentsDraft.QueryAsync(app, schema, odataQuery, status, true);
}
} }
} }
public Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchemaEntity schema, Status[] status, HashSet<Guid> ids) public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchemaEntity schema, Status[] status, HashSet<Guid> ids)
{
using (Profiler.TraceMethod<MongoContentRepository>("QueryAsyncByIds"))
{ {
if (RequiresPublished(status)) if (RequiresPublished(status))
{ {
return contentsPublished.QueryAsync(app, schema, ids); return await contentsPublished.QueryAsync(app, schema, ids);
} }
else else
{ {
return contentsDraft.QueryAsync(app, schema, ids, status); return await contentsDraft.QueryAsync(app, schema, ids, status);
}
} }
} }
public Task<IContentEntity> FindContentAsync(IAppEntity app, ISchemaEntity schema, Status[] status, Guid id) public async Task<IContentEntity> FindContentAsync(IAppEntity app, ISchemaEntity schema, Status[] status, Guid id)
{
using (Profiler.TraceMethod<MongoContentRepository>())
{ {
if (RequiresPublished(status)) if (RequiresPublished(status))
{ {
return contentsPublished.FindContentAsync(app, schema, id); return await contentsPublished.FindContentAsync(app, schema, id);
} }
else else
{ {
return contentsDraft.FindContentAsync(app, schema, id); return await contentsDraft.FindContentAsync(app, schema, id);
}
} }
} }
public Task<IReadOnlyList<Guid>> QueryNotFoundAsync(Guid appId, Guid schemaId, IList<Guid> ids) public async Task<IReadOnlyList<Guid>> QueryNotFoundAsync(Guid appId, Guid schemaId, IList<Guid> ids)
{
using (Profiler.TraceMethod<MongoContentRepository>())
{ {
return contentsDraft.QueryNotFoundAsync(appId, schemaId, ids); await contentsDraft.QueryNotFoundAsync(appId, schemaId, ids);
}
} }
public Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntity, Task> callback) public async Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntity, Task> callback)
{ {
return contentsDraft.QueryScheduledWithoutDataAsync(now, callback); using (Profiler.TraceMethod<MongoContentRepository>())
{
await contentsDraft.QueryScheduledWithoutDataAsync(now, callback);
}
} }
public Task ClearAsync() public Task ClearAsync()

11
src/Squidex.Domain.Apps.Entities.MongoDb/Contents/MongoContentRepository_SnapshotStore.cs

@ -12,6 +12,7 @@ using Squidex.Domain.Apps.Core.ConvertContent;
using Squidex.Domain.Apps.Entities.Contents.State; using Squidex.Domain.Apps.Entities.Contents.State;
using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
@ -19,12 +20,17 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
{ {
public partial class MongoContentRepository : ISnapshotStore<ContentState, Guid> public partial class MongoContentRepository : ISnapshotStore<ContentState, Guid>
{ {
public Task<(ContentState Value, long Version)> ReadAsync(Guid key) public async Task<(ContentState Value, long Version)> ReadAsync(Guid key)
{ {
return contentsDraft.ReadAsync(key, GetSchemaAsync); using (Profiler.TraceMethod<MongoContentRepository>())
{
return await contentsDraft.ReadAsync(key, GetSchemaAsync);
}
} }
public async Task WriteAsync(Guid key, ContentState value, long oldVersion, long newVersion) public async Task WriteAsync(Guid key, ContentState value, long oldVersion, long newVersion)
{
using (Profiler.TraceMethod<MongoContentRepository>())
{ {
if (value.SchemaId.Id == Guid.Empty) if (value.SchemaId.Id == Guid.Empty)
{ {
@ -58,6 +64,7 @@ namespace Squidex.Domain.Apps.Entities.MongoDb.Contents
await contentsPublished.RemoveAsync(content.Id); await contentsPublished.RemoveAsync(content.Id);
} }
} }
}
private async Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid schemaId) private async Task<ISchemaEntity> GetSchemaAsync(Guid appId, Guid schemaId)
{ {

16
src/Squidex.Domain.Apps.Entities/Contents/ContentQueryService.cs

@ -20,6 +20,7 @@ using Squidex.Domain.Apps.Entities.Contents.Edm;
using Squidex.Domain.Apps.Entities.Contents.Repositories; using Squidex.Domain.Apps.Entities.Contents.Repositories;
using Squidex.Domain.Apps.Entities.Schemas; using Squidex.Domain.Apps.Entities.Schemas;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.Reflection; using Squidex.Infrastructure.Reflection;
using Squidex.Infrastructure.Security; using Squidex.Infrastructure.Security;
@ -71,6 +72,8 @@ namespace Squidex.Domain.Apps.Entities.Contents
var schema = await GetSchemaAsync(app, schemaIdOrName); var schema = await GetSchemaAsync(app, schemaIdOrName);
using (Profiler.TraceMethod<ContentQueryService>())
{
var isVersioned = version > EtagVersion.Empty; var isVersioned = version > EtagVersion.Empty;
var isFrontend = IsFrontendClient(user); var isFrontend = IsFrontendClient(user);
@ -88,6 +91,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
return TransformContent(app, schema, user, content, isFrontend, isVersioned); return TransformContent(app, schema, user, content, isFrontend, isVersioned);
} }
}
public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, string schemaIdOrName, ClaimsPrincipal user, bool archived, string query) public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, string schemaIdOrName, ClaimsPrincipal user, bool archived, string query)
{ {
@ -97,6 +101,8 @@ namespace Squidex.Domain.Apps.Entities.Contents
var schema = await GetSchemaAsync(app, schemaIdOrName); var schema = await GetSchemaAsync(app, schemaIdOrName);
using (Profiler.TraceMethod<ContentQueryService>("QueryAsyncByQuery"))
{
var isFrontend = IsFrontendClient(user); var isFrontend = IsFrontendClient(user);
var parsedQuery = ParseQuery(app, query, schema); var parsedQuery = ParseQuery(app, query, schema);
@ -106,6 +112,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
return TransformContents(app, schema, user, contents, false, isFrontend); return TransformContents(app, schema, user, contents, false, isFrontend);
} }
}
public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, string schemaIdOrName, ClaimsPrincipal user, bool archived, HashSet<Guid> ids) public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, string schemaIdOrName, ClaimsPrincipal user, bool archived, HashSet<Guid> ids)
{ {
@ -116,6 +123,8 @@ namespace Squidex.Domain.Apps.Entities.Contents
var schema = await GetSchemaAsync(app, schemaIdOrName); var schema = await GetSchemaAsync(app, schemaIdOrName);
using (Profiler.TraceMethod<ContentQueryService>("QueryAsyncByIds"))
{
var isFrontend = IsFrontendClient(user); var isFrontend = IsFrontendClient(user);
var parsedStatus = ParseStatus(isFrontend, archived); var parsedStatus = ParseStatus(isFrontend, archived);
@ -124,6 +133,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
return TransformContents(app, schema, user, contents, false, isFrontend); return TransformContents(app, schema, user, contents, false, isFrontend);
} }
}
private IContentEntity TransformContent(IAppEntity app, ISchemaEntity schema, ClaimsPrincipal user, private IContentEntity TransformContent(IAppEntity app, ISchemaEntity schema, ClaimsPrincipal user,
IContentEntity content, IContentEntity content,
@ -147,6 +157,8 @@ namespace Squidex.Domain.Apps.Entities.Contents
IEnumerable<IContentEntity> contents, IEnumerable<IContentEntity> contents,
bool isTypeChecking, bool isTypeChecking,
bool isFrontendClient) bool isFrontendClient)
{
using (Profiler.TraceMethod<ContentQueryService>())
{ {
var scriptText = schema.ScriptQuery; var scriptText = schema.ScriptQuery;
@ -174,8 +186,11 @@ namespace Squidex.Domain.Apps.Entities.Contents
yield return result; yield return result;
} }
} }
}
private ODataUriParser ParseQuery(IAppEntity app, string query, ISchemaEntity schema) private ODataUriParser ParseQuery(IAppEntity app, string query, ISchemaEntity schema)
{
using (Profiler.TraceMethod<ContentQueryService>())
{ {
try try
{ {
@ -188,6 +203,7 @@ namespace Squidex.Domain.Apps.Entities.Contents
throw new ValidationException($"Failed to parse query: {ex.Message}", ex); throw new ValidationException($"Failed to parse query: {ex.Message}", ex);
} }
} }
}
public async Task<ISchemaEntity> GetSchemaAsync(IAppEntity app, string schemaIdOrName) public async Task<ISchemaEntity> GetSchemaAsync(IAppEntity app, string schemaIdOrName)
{ {

4
src/Squidex.Domain.Apps.Entities/Contents/ContentVersionLoader.cs

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using Squidex.Domain.Apps.Core.Schemas; using Squidex.Domain.Apps.Core.Schemas;
using Squidex.Domain.Apps.Entities.Contents.State; using Squidex.Domain.Apps.Entities.Contents.State;
using Squidex.Infrastructure; using Squidex.Infrastructure;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.States; using Squidex.Infrastructure.States;
namespace Squidex.Domain.Apps.Entities.Contents namespace Squidex.Domain.Apps.Entities.Contents
@ -30,6 +31,8 @@ namespace Squidex.Domain.Apps.Entities.Contents
} }
public async Task<IContentEntity> LoadAsync(Guid id, long version) public async Task<IContentEntity> LoadAsync(Guid id, long version)
{
using (Profiler.TraceMethod<ContentVersionLoader>())
{ {
var content = new ContentState(); var content = new ContentState();
@ -52,4 +55,5 @@ namespace Squidex.Domain.Apps.Entities.Contents
return content; return content;
} }
} }
}
} }

13
src/Squidex.Infrastructure.GetEventStore/EventSourcing/GetEventStore.cs

@ -11,6 +11,7 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using EventStore.ClientAPI; using EventStore.ClientAPI;
using Squidex.Infrastructure.Log;
namespace Squidex.Infrastructure.EventSourcing namespace Squidex.Infrastructure.EventSourcing
{ {
@ -58,6 +59,8 @@ namespace Squidex.Infrastructure.EventSourcing
} }
public async Task QueryAsync(Func<StoredEvent, Task> callback, string property, object value, string position = null, CancellationToken ct = default(CancellationToken)) public async Task QueryAsync(Func<StoredEvent, Task> callback, string property, object value, string position = null, CancellationToken ct = default(CancellationToken))
{
using (Profiler.TraceMethod<GetEventStore>())
{ {
var streamName = await projectionClient.CreateProjectionAsync(property, value); var streamName = await projectionClient.CreateProjectionAsync(property, value);
@ -65,8 +68,11 @@ namespace Squidex.Infrastructure.EventSourcing
await QueryAsync(callback, streamName, sliceStart, ct); await QueryAsync(callback, streamName, sliceStart, ct);
} }
}
public async Task QueryAsync(Func<StoredEvent, Task> callback, string streamFilter = null, string position = null, CancellationToken ct = default(CancellationToken)) public async Task QueryAsync(Func<StoredEvent, Task> callback, string streamFilter = null, string position = null, CancellationToken ct = default(CancellationToken))
{
using (Profiler.TraceMethod<GetEventStore>())
{ {
var streamName = await projectionClient.CreateProjectionAsync(streamFilter); var streamName = await projectionClient.CreateProjectionAsync(streamFilter);
@ -74,6 +80,7 @@ namespace Squidex.Infrastructure.EventSourcing
await QueryAsync(callback, streamName, sliceStart, ct); await QueryAsync(callback, streamName, sliceStart, ct);
} }
}
private Task QueryAsync(Func<StoredEvent, Task> callback, string streamName, long sliceStart, CancellationToken ct) private Task QueryAsync(Func<StoredEvent, Task> callback, string streamName, long sliceStart, CancellationToken ct)
{ {
@ -81,6 +88,8 @@ namespace Squidex.Infrastructure.EventSourcing
} }
public async Task<IReadOnlyList<StoredEvent>> QueryAsync(string streamName, long streamPosition = 0) public async Task<IReadOnlyList<StoredEvent>> QueryAsync(string streamName, long streamPosition = 0)
{
using (Profiler.TraceMethod<GetEventStore>())
{ {
var result = new List<StoredEvent>(); var result = new List<StoredEvent>();
@ -107,6 +116,7 @@ namespace Squidex.Infrastructure.EventSourcing
return result; return result;
} }
}
public Task AppendAsync(Guid commitId, string streamName, ICollection<EventData> events) public Task AppendAsync(Guid commitId, string streamName, ICollection<EventData> events)
{ {
@ -121,6 +131,8 @@ namespace Squidex.Infrastructure.EventSourcing
} }
private async Task AppendEventsInternalAsync(string streamName, long expectedVersion, ICollection<EventData> events) private async Task AppendEventsInternalAsync(string streamName, long expectedVersion, ICollection<EventData> events)
{
using (Profiler.TraceMethod<GetEventStore>(nameof(AppendAsync)))
{ {
Guard.NotNullOrEmpty(streamName, nameof(streamName)); Guard.NotNullOrEmpty(streamName, nameof(streamName));
Guard.NotNull(events, nameof(events)); Guard.NotNull(events, nameof(events));
@ -149,6 +161,7 @@ namespace Squidex.Infrastructure.EventSourcing
} }
} }
} }
}
private string GetStreamName(string streamName) private string GetStreamName(string streamName)
{ {

11
src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore_Reader.cs

@ -10,6 +10,7 @@ using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver; using MongoDB.Driver;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.MongoDb; using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.EventSourcing namespace Squidex.Infrastructure.EventSourcing
@ -30,6 +31,8 @@ namespace Squidex.Infrastructure.EventSourcing
} }
public async Task<IReadOnlyList<StoredEvent>> QueryAsync(string streamName, long streamPosition = 0) public async Task<IReadOnlyList<StoredEvent>> QueryAsync(string streamName, long streamPosition = 0)
{
using (Profiler.TraceMethod<MongoEventStore>())
{ {
var commits = var commits =
await Collection.Find( await Collection.Find(
@ -63,6 +66,7 @@ namespace Squidex.Infrastructure.EventSourcing
return result; return result;
} }
}
public Task QueryAsync(Func<StoredEvent, Task> callback, string property, object value, string position = null, CancellationToken ct = default(CancellationToken)) public Task QueryAsync(Func<StoredEvent, Task> callback, string property, object value, string position = null, CancellationToken ct = default(CancellationToken))
{ {
@ -86,9 +90,11 @@ namespace Squidex.Infrastructure.EventSourcing
return QueryAsync(callback, lastPosition, filter, ct); return QueryAsync(callback, lastPosition, filter, ct);
} }
private Task QueryAsync(Func<StoredEvent, Task> callback, StreamPosition lastPosition, FilterDefinition<MongoEventCommit> filter, CancellationToken ct) private async Task QueryAsync(Func<StoredEvent, Task> callback, StreamPosition lastPosition, FilterDefinition<MongoEventCommit> filter, CancellationToken ct)
{ {
return Collection.Find(filter).Sort(Sort.Ascending(TimestampField)).ForEachPipelineAsync(async commit => using (Profiler.TraceMethod<MongoEventStore>())
{
await Collection.Find(filter).Sort(Sort.Ascending(TimestampField)).ForEachPipelineAsync(async commit =>
{ {
var eventStreamOffset = (int)commit.EventStreamOffset; var eventStreamOffset = (int)commit.EventStreamOffset;
@ -111,6 +117,7 @@ namespace Squidex.Infrastructure.EventSourcing
} }
}, ct); }, ct);
} }
}
private static FilterDefinition<MongoEventCommit> CreateFilter(string property, object value, StreamPosition streamPosition) private static FilterDefinition<MongoEventCommit> CreateFilter(string property, object value, StreamPosition streamPosition)
{ {

4
src/Squidex.Infrastructure.MongoDb/EventSourcing/MongoEventStore_Writer.cs

@ -11,6 +11,7 @@ using System.Reactive.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
using Squidex.Infrastructure.Log;
namespace Squidex.Infrastructure.EventSourcing namespace Squidex.Infrastructure.EventSourcing
{ {
@ -25,6 +26,8 @@ namespace Squidex.Infrastructure.EventSourcing
} }
public async Task AppendAsync(Guid commitId, string streamName, long expectedVersion, ICollection<EventData> events) public async Task AppendAsync(Guid commitId, string streamName, long expectedVersion, ICollection<EventData> events)
{
using (Profiler.TraceMethod<MongoEventStore>())
{ {
Guard.GreaterEquals(expectedVersion, EtagVersion.Any, nameof(expectedVersion)); Guard.GreaterEquals(expectedVersion, EtagVersion.Any, nameof(expectedVersion));
Guard.NotNullOrEmpty(streamName, nameof(streamName)); Guard.NotNullOrEmpty(streamName, nameof(streamName));
@ -81,6 +84,7 @@ namespace Squidex.Infrastructure.EventSourcing
} }
} }
} }
}
private async Task<long> GetEventStreamOffset(string streamName) private async Task<long> GetEventStreamOffset(string streamName)
{ {

16
src/Squidex.Infrastructure.MongoDb/States/MongoSnapshotStore.cs

@ -10,6 +10,7 @@ using System.Threading.Tasks;
using MongoDB.Bson; using MongoDB.Bson;
using MongoDB.Driver; using MongoDB.Driver;
using Newtonsoft.Json; using Newtonsoft.Json;
using Squidex.Infrastructure.Log;
using Squidex.Infrastructure.MongoDb; using Squidex.Infrastructure.MongoDb;
namespace Squidex.Infrastructure.States namespace Squidex.Infrastructure.States
@ -36,6 +37,8 @@ namespace Squidex.Infrastructure.States
} }
public async Task<(T Value, long Version)> ReadAsync(TKey key) public async Task<(T Value, long Version)> ReadAsync(TKey key)
{
using (Profiler.TraceMethod<MongoSnapshotStore<T, TKey>>())
{ {
var existing = var existing =
await Collection.Find(x => x.Id.Equals(key)) await Collection.Find(x => x.Id.Equals(key))
@ -48,15 +51,22 @@ namespace Squidex.Infrastructure.States
return (default(T), EtagVersion.NotFound); return (default(T), EtagVersion.NotFound);
} }
}
public Task WriteAsync(TKey key, T value, long oldVersion, long newVersion) public async Task WriteAsync(TKey key, T value, long oldVersion, long newVersion)
{
using (Profiler.TraceMethod<MongoSnapshotStore<T, TKey>>())
{ {
return Collection.UpsertVersionedAsync(key, oldVersion, newVersion, u => u.Set(x => x.Doc, value)); await Collection.UpsertVersionedAsync(key, oldVersion, newVersion, u => u.Set(x => x.Doc, value));
}
} }
public Task ReadAllAsync(System.Func<T, long, Task> callback) public async Task ReadAllAsync(System.Func<T, long, Task> callback)
{
using (Profiler.TraceMethod<MongoSnapshotStore<T, TKey>>())
{ {
return Collection.Find(new BsonDocument()).ForEachAsync(x => callback(x.Doc, x.Version)); return Collection.Find(new BsonDocument()).ForEachAsync(x => callback(x.Doc, x.Version));
} }
} }
}
} }

Loading…
Cancel
Save