Skip to content

Commit f254399

Browse files
Scope Fusion document cache to schema, but not executor
1 parent a4a971a commit f254399

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/DependencyInjection/HotChocolateFusionServiceCollectionExtensions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using HotChocolate.Fusion.Configuration;
44
using HotChocolate.Fusion.Execution;
55
using HotChocolate.Fusion.Execution.Clients;
6+
using HotChocolate.Language;
67
using Microsoft.Extensions.DependencyInjection.Extensions;
78
using Microsoft.Extensions.ObjectPool;
89
using Microsoft.Extensions.Options;
@@ -74,7 +75,30 @@ private static DefaultFusionGatewayBuilder CreateBuilder(
7475
}
7576

7677
var builder = new DefaultFusionGatewayBuilder(services, name);
78+
builder.AddDocumentCache();
7779
builder.UseDefaultPipeline();
7880
return builder;
7981
}
82+
83+
private static IFusionGatewayBuilder AddDocumentCache(this IFusionGatewayBuilder builder)
84+
{
85+
builder.Services.TryAddKeyedSingleton<IDocumentCache>(
86+
builder.Name,
87+
static (sp, schemaName) =>
88+
{
89+
var optionsMonitor = sp.GetRequiredService<IOptionsMonitor<FusionGatewaySetup>>();
90+
var setup = optionsMonitor.Get((string)schemaName!);
91+
92+
var options = FusionRequestExecutorManager.CreateOptions(setup);
93+
94+
return new DefaultDocumentCache(options.OperationDocumentCacheSize);
95+
});
96+
97+
return builder.ConfigureSchemaServices(
98+
static (sp, s) => s.AddSingleton<IDocumentCache>(schemaServices =>
99+
{
100+
var schemaName = schemaServices.GetRequiredService<ISchemaDefinition>().Name;
101+
return sp.GetRequiredKeyedService<IDocumentCache>(schemaName);
102+
}));
103+
}
80104
}

src/HotChocolate/Fusion-vnext/src/Fusion.Execution/Execution/FusionRequestExecutorManager.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,12 +431,6 @@ private static void AddParserServices(IServiceCollection services)
431431
{
432432
services.AddSingleton<IDocumentHashProvider>(static _ => new MD5DocumentHashProvider(HashFormat.Hex));
433433
services.AddSingleton(static sp => sp.GetRequiredService<ISchemaDefinition>().GetParserOptions());
434-
services.AddSingleton<IDocumentCache>(
435-
static sp =>
436-
{
437-
var options = sp.GetRequiredService<ISchemaDefinition>().GetOptions();
438-
return new DefaultDocumentCache(options.OperationDocumentCacheSize);
439-
});
440434
}
441435

442436
private void AddDocumentValidator(

0 commit comments

Comments
 (0)