|
|
|
@ -15,6 +15,7 @@ using Squidex.Domain.Apps.Core; |
|
|
|
using Squidex.Domain.Apps.Entities.Assets; |
|
|
|
using Squidex.Domain.Apps.Entities.Contents.GraphQL.Types; |
|
|
|
using Squidex.Domain.Apps.Entities.Contents.Queries; |
|
|
|
using Squidex.Infrastructure; |
|
|
|
using Squidex.Infrastructure.Json.Objects; |
|
|
|
using Squidex.Infrastructure.Log; |
|
|
|
|
|
|
|
@ -70,37 +71,37 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
return await dataLoader.LoadAsync(id); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<IReadOnlyList<IEnrichedAssetEntity>> GetReferencedAssetsAsync(IJsonValue value) |
|
|
|
public Task<IReadOnlyList<IEnrichedAssetEntity>> GetReferencedAssetsAsync(IJsonValue value) |
|
|
|
{ |
|
|
|
var ids = ParseIds(value); |
|
|
|
|
|
|
|
if (ids == null) |
|
|
|
{ |
|
|
|
return EmptyAssets; |
|
|
|
return Task.FromResult<IReadOnlyList<IEnrichedAssetEntity>>(EmptyAssets); |
|
|
|
} |
|
|
|
|
|
|
|
var dataLoader = GetAssetsLoader(); |
|
|
|
|
|
|
|
return await dataLoader.LoadManyAsync(ids); |
|
|
|
return LoadManyAsync(dataLoader, ids); |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<IReadOnlyList<IContentEntity>> GetReferencedContentsAsync(IJsonValue value) |
|
|
|
public Task<IReadOnlyList<IContentEntity>> GetReferencedContentsAsync(IJsonValue value) |
|
|
|
{ |
|
|
|
var ids = ParseIds(value); |
|
|
|
|
|
|
|
if (ids == null) |
|
|
|
{ |
|
|
|
return EmptyContents; |
|
|
|
return Task.FromResult<IReadOnlyList<IContentEntity>>(EmptyContents); |
|
|
|
} |
|
|
|
|
|
|
|
var dataLoader = GetContentsLoader(); |
|
|
|
|
|
|
|
return await dataLoader.LoadManyAsync(ids); |
|
|
|
return LoadManyAsync(dataLoader, ids); |
|
|
|
} |
|
|
|
|
|
|
|
private IDataLoader<Guid, IEnrichedAssetEntity> GetAssetsLoader() |
|
|
|
{ |
|
|
|
return dataLoaderContextAccessor.Context.GetOrAddBatchLoader<Guid, IEnrichedAssetEntity>("Assets", |
|
|
|
return dataLoaderContextAccessor.Context.GetOrAddBatchLoader<Guid, IEnrichedAssetEntity>(nameof(GetAssetsLoader), |
|
|
|
async batch => |
|
|
|
{ |
|
|
|
var result = await GetReferencedAssetsAsync(new List<Guid>(batch)); |
|
|
|
@ -111,7 +112,7 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
|
|
|
|
private IDataLoader<Guid, IContentEntity> GetContentsLoader() |
|
|
|
{ |
|
|
|
return dataLoaderContextAccessor.Context.GetOrAddBatchLoader<Guid, IContentEntity>("References", |
|
|
|
return dataLoaderContextAccessor.Context.GetOrAddBatchLoader<Guid, IContentEntity>(nameof(GetContentsLoader), |
|
|
|
async batch => |
|
|
|
{ |
|
|
|
var result = await GetReferencedContentsAsync(new List<Guid>(batch)); |
|
|
|
@ -120,6 +121,13 @@ namespace Squidex.Domain.Apps.Entities.Contents.GraphQL |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
private static async Task<IReadOnlyList<T>> LoadManyAsync<TKey, T>(IDataLoader<TKey, T> dataLoader, ICollection<TKey> keys) where T : class |
|
|
|
{ |
|
|
|
var contents = await Task.WhenAll(keys.Select(dataLoader.LoadAsync)); |
|
|
|
|
|
|
|
return contents.NotNull().ToList(); |
|
|
|
} |
|
|
|
|
|
|
|
private static ICollection<Guid>? ParseIds(IJsonValue value) |
|
|
|
{ |
|
|
|
try |
|
|
|
|