Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Squidex/squidex
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianStehle committed Sep 14, 2021
2 parents 09a4c7f + 095a10f commit cb7b101
Show file tree
Hide file tree
Showing 31 changed files with 89 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ protected override Task SetupCollectionAsync(IMongoCollection<MongoAssetFolderEn
public async Task<IResultList<IAssetFolderEntity>> QueryAsync(DomainId appId, DomainId parentId,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>("QueryAsyncByQuery"))
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/QueryAsync"))
{
var filter = BuildFilter(appId, parentId);

Expand All @@ -60,7 +60,7 @@ await Collection.Find(filter).SortBy(x => x.FolderName)
public async Task<IReadOnlyList<DomainId>> QueryChildIdsAsync(DomainId appId, DomainId parentId,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/QueryChildIdsAsync"))
{
var filter = BuildFilter(appId, parentId);

Expand All @@ -77,7 +77,7 @@ await Collection.Find(filter).Only(x => x.Id)
public async Task<IAssetFolderEntity?> FindAssetFolderAsync(DomainId appId, DomainId id,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/FindAssetFolderAsync"))
{
var documentId = DomainId.Combine(appId, id);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class MongoAssetFolderRepository : ISnapshotStore<AssetFol
{
async Task<(AssetFolderDomainObject.State Value, bool Valid, long Version)> ISnapshotStore<AssetFolderDomainObject.State>.ReadAsync(DomainId key)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/ReadAsync"))
{
var existing =
await Collection.Find(x => x.DocumentId == key)
Expand All @@ -41,7 +41,7 @@ await Collection.Find(x => x.DocumentId == key)

async Task ISnapshotStore<AssetFolderDomainObject.State>.WriteAsync(DomainId key, AssetFolderDomainObject.State value, long oldVersion, long newVersion)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/WriteAsync"))
{
var entity = Map(value);

Expand All @@ -51,7 +51,7 @@ await Collection.Find(x => x.DocumentId == key)

async Task ISnapshotStore<AssetFolderDomainObject.State>.WriteManyAsync(IEnumerable<(DomainId Key, AssetFolderDomainObject.State Value, long Version)> snapshots)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/WriteManyAsync"))
{
var updates = snapshots.Select(Map).Select(x =>
new ReplaceOneModel<MongoAssetFolderEntity>(
Expand All @@ -73,15 +73,15 @@ await Collection.Find(x => x.DocumentId == key)
async Task ISnapshotStore<AssetFolderDomainObject.State>.ReadAllAsync(Func<AssetFolderDomainObject.State, long, Task> callback,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/ReadAllAsync"))
{
await Collection.Find(new BsonDocument(), Batching.Options).ForEachAsync(x => callback(Map(x), x.Version), ct);
}
}

async Task ISnapshotStore<AssetFolderDomainObject.State>.RemoveAsync(DomainId key)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetFolderRepository/RemoveAsync"))
{
await Collection.DeleteOneAsync(x => x.DocumentId == key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public async IAsyncEnumerable<IAssetEntity> StreamAll(DomainId appId,
public async Task<IResultList<IAssetEntity>> QueryAsync(DomainId appId, DomainId? parentId, Q q,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>("QueryAsyncByQuery"))
using (Telemetry.Activities.StartActivity("ContentQueryService/QueryAsync"))
{
try
{
Expand Down Expand Up @@ -152,7 +152,7 @@ await Collection.Find(filter)
public async Task<IReadOnlyList<DomainId>> QueryIdsAsync(DomainId appId, HashSet<DomainId> ids,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>("QueryAsyncByIds"))
using (Telemetry.Activities.StartActivity("ContentQueryService/QueryIdsAsync"))
{
var assetEntities =
await Collection.Find(BuildFilter(appId, ids)).Only(x => x.Id)
Expand All @@ -167,7 +167,7 @@ await Collection.Find(BuildFilter(appId, ids)).Only(x => x.Id)
public async Task<IReadOnlyList<DomainId>> QueryChildIdsAsync(DomainId appId, DomainId parentId,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("ContentQueryService/QueryChildIdsAsync"))
{
var assetEntities =
await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.ParentId == parentId).Only(x => x.Id)
Expand All @@ -182,7 +182,7 @@ await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.ParentId
public async Task<IAssetEntity?> FindAssetByHashAsync(DomainId appId, string hash, string fileName, long fileSize,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("ContentQueryService/FindAssetByHashAsync"))
{
var assetEntity =
await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.FileHash == hash && x.FileName == fileName && x.FileSize == fileSize)
Expand All @@ -195,7 +195,7 @@ await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.FileHash
public async Task<IAssetEntity?> FindAssetBySlugAsync(DomainId appId, string slug,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("ContentQueryService/FindAssetBySlugAsync"))
{
var assetEntity =
await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.Slug == slug)
Expand All @@ -208,7 +208,7 @@ await Collection.Find(x => x.IndexedAppId == appId && !x.IsDeleted && x.Slug ==
public async Task<IAssetEntity?> FindAssetAsync(DomainId appId, DomainId id,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("ContentQueryService/FindAssetAsync"))
{
var documentId = DomainId.Combine(appId, id);

Expand All @@ -223,7 +223,7 @@ await Collection.Find(x => x.DocumentId == documentId && !x.IsDeleted)
public async Task<IAssetEntity?> FindAssetAsync(DomainId id,
CancellationToken ct = default)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("ContentQueryService/FindAssetAsync"))
{
var assetEntity =
await Collection.Find(x => x.Id == id && !x.IsDeleted)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public sealed partial class MongoAssetRepository : ISnapshotStore<AssetDomainObj
{
async Task<(AssetDomainObject.State Value, bool Valid, long Version)> ISnapshotStore<AssetDomainObject.State>.ReadAsync(DomainId key)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetRepository/ReadAsync"))
{
var existing =
await Collection.Find(x => x.DocumentId == key)
Expand All @@ -41,7 +41,7 @@ await Collection.Find(x => x.DocumentId == key)

async Task ISnapshotStore<AssetDomainObject.State>.WriteAsync(DomainId key, AssetDomainObject.State value, long oldVersion, long newVersion)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetRepository/WriteAsync"))
{
var entity = Map(value);

Expand All @@ -51,7 +51,7 @@ await Collection.Find(x => x.DocumentId == key)

async Task ISnapshotStore<AssetDomainObject.State>.WriteManyAsync(IEnumerable<(DomainId Key, AssetDomainObject.State Value, long Version)> snapshots)
{
using (Telemetry.Activities.StartMethod<MongoAssetFolderRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetRepository/WriteManyAsync"))
{
var updates = snapshots.Select(Map).Select(x =>
new ReplaceOneModel<MongoAssetEntity>(
Expand All @@ -73,15 +73,15 @@ await Collection.Find(x => x.DocumentId == key)
async Task ISnapshotStore<AssetDomainObject.State>.ReadAllAsync(Func<AssetDomainObject.State, long, Task> callback,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetRepository/ReadAllAsync"))
{
await Collection.Find(new BsonDocument(), Batching.Options).ForEachAsync(x => callback(Map(x), x.Version), ct);
}
}

async Task ISnapshotStore<AssetDomainObject.State>.RemoveAsync(DomainId key)
{
using (Telemetry.Activities.StartMethod<MongoAssetRepository>())
using (Telemetry.Activities.StartActivity("MongoAssetRepository/RemoveAsync"))
{
await Collection.DeleteOneAsync(x => x.DocumentId == key);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public IAsyncEnumerable<IContentEntity> StreamAll(DomainId appId, HashSet<Domain
public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, List<ISchemaEntity> schemas, Q q,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryAsync"))
{
if (q.Ids != null && q.Ids.Count > 0)
{
Expand Down Expand Up @@ -135,7 +135,7 @@ public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, List<I
public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchemaEntity schema, Q q,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryAsync"))
{
if (q.Ids != null && q.Ids.Count > 0)
{
Expand All @@ -159,7 +159,7 @@ public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchem
public async Task<IContentEntity?> FindContentAsync(ISchemaEntity schema, DomainId id,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/FindContentAsync"))
{
return await queryBdId.QueryAsync(schema, id, ct);
}
Expand All @@ -168,7 +168,7 @@ public async Task<IResultList<IContentEntity>> QueryAsync(IAppEntity app, ISchem
public async Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntity, Task> callback,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryScheduledWithoutDataAsync"))
{
await queryScheduled.QueryAsync(now, callback, ct);
}
Expand All @@ -177,7 +177,7 @@ public async Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntit
public async Task<IReadOnlyList<(DomainId SchemaId, DomainId Id, Status Status)>> QueryIdsAsync(DomainId appId, HashSet<DomainId> ids,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryIdsAsync"))
{
return await queryByIds.QueryIdsAsync(appId, ids, ct);
}
Expand All @@ -186,7 +186,7 @@ public async Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntit
public async Task<IReadOnlyList<(DomainId SchemaId, DomainId Id, Status Status)>> QueryIdsAsync(DomainId appId, DomainId schemaId, FilterNode<ClrValue> filterNode,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/QueryIdsAsync"))
{
return await queryByQuery.QueryIdsAsync(appId, schemaId, filterNode, ct);
}
Expand All @@ -195,7 +195,7 @@ public async Task QueryScheduledWithoutDataAsync(Instant now, Func<IContentEntit
public async Task<bool> HasReferrersAsync(DomainId appId, DomainId contentId,
CancellationToken ct)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentCollection/HasReferrersAsync"))
{
return await queryReferrers.CheckExistsAsync(appId, contentId, ct);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public partial class MongoContentRepository : ISnapshotStore<ContentDomainObject

async Task<(ContentDomainObject.State Value, bool Valid, long Version)> ISnapshotStore<ContentDomainObject.State>.ReadAsync(DomainId key)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentRepository/ReadAsync"))
{
var version = await collectionAll.FindVersionAsync(key);

Expand All @@ -38,7 +38,7 @@ public partial class MongoContentRepository : ISnapshotStore<ContentDomainObject

async Task ISnapshotStore<ContentDomainObject.State>.ClearAsync()
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentRepository/ClearAsync"))
{
await collectionAll.ClearAsync();
await collectionPublished.ClearAsync();
Expand All @@ -47,7 +47,7 @@ public partial class MongoContentRepository : ISnapshotStore<ContentDomainObject

async Task ISnapshotStore<ContentDomainObject.State>.RemoveAsync(DomainId key)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentRepository/RemoveAsync"))
{
await collectionAll.RemoveAsync(key);
await collectionPublished.RemoveAsync(key);
Expand All @@ -56,7 +56,7 @@ public partial class MongoContentRepository : ISnapshotStore<ContentDomainObject

async Task ISnapshotStore<ContentDomainObject.State>.WriteAsync(DomainId key, ContentDomainObject.State value, long oldVersion, long newVersion)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentRepository/WriteAsync"))
{
if (value.SchemaId.Id == DomainId.Empty)
{
Expand All @@ -71,7 +71,7 @@ await Task.WhenAll(

async Task ISnapshotStore<ContentDomainObject.State>.WriteManyAsync(IEnumerable<(DomainId Key, ContentDomainObject.State Value, long Version)> snapshots)
{
using (Telemetry.Activities.StartMethod<MongoContentRepository>())
using (Telemetry.Activities.StartActivity("MongoContentRepository/WriteManyAsync"))
{
var entitiesPublished = new List<MongoContentEntity>();
var entitiesAll = new List<MongoContentEntity>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public Task<bool> AddAsync(string? token)

public async Task<List<IAppEntity>> GetAppsAsync()
{
using (Telemetry.Activities.StartMethod<AppsIndex>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppsAsync"))
{
var ids = await GetAppIdsAsync();

Expand All @@ -90,7 +90,7 @@ await Task.WhenAll(ids

public async Task<List<IAppEntity>> GetAppsForUserAsync(string userId, PermissionSet permissions)
{
using (Telemetry.Activities.StartMethod<AppsIndex>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppsForUserAsync"))
{
var ids =
await Task.WhenAll(
Expand All @@ -108,7 +108,7 @@ await Task.WhenAll(ids

public async Task<IAppEntity?> GetAppByNameAsync(string name, bool canCache = false)
{
using (Telemetry.Activities.StartMethod<AppsIndex>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppByNameAsync"))
{
if (canCache)
{
Expand All @@ -131,7 +131,7 @@ await Task.WhenAll(ids

public async Task<IAppEntity?> GetAppAsync(DomainId appId, bool canCache)
{
using (Telemetry.Activities.StartMethod<AppsIndex>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppAsync"))
{
if (canCache)
{
Expand All @@ -154,31 +154,31 @@ await Task.WhenAll(ids

private async Task<List<DomainId>> GetAppIdsByUserAsync(string userId)
{
using (Telemetry.Activities.StartMethod<AppProvider>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppIdsByUserAsync"))
{
return await grainFactory.GetGrain<IAppsByUserIndexGrain>(userId).GetIdsAsync();
}
}

private async Task<List<DomainId>> GetAppIdsAsync()
{
using (Telemetry.Activities.StartMethod<AppProvider>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAllAppIdsAsync"))
{
return await grainFactory.GetGrain<IAppsByNameIndexGrain>(SingleGrain.Id).GetIdsAsync();
}
}

private async Task<List<DomainId>> GetAppIdsAsync(string[] names)
{
using (Telemetry.Activities.StartMethod<AppProvider>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppIdsAsync"))
{
return await grainFactory.GetGrain<IAppsByNameIndexGrain>(SingleGrain.Id).GetIdsAsync(names);
}
}

private async Task<DomainId> GetAppIdAsync(string name)
{
using (Telemetry.Activities.StartMethod<AppProvider>())
using (Telemetry.Activities.StartActivity("AppProvider/GetAppIdAsync"))
{
return await grainFactory.GetGrain<IAppsByNameIndexGrain>(SingleGrain.Id).GetIdAsync(name);
}
Expand Down
Loading

0 comments on commit cb7b101

Please sign in to comment.