Skip to content

Commit 7805e83

Browse files
Copilotxperiandri
andauthored
Cache schema ID at Executor level to avoid recomputing on every request
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/38a5449a-9904-46f6-b33a-acf9f32a7151 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent 38a67ad commit 7805e83

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

src/FSharp.Data.GraphQL.Server/Executor.fs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ type ExecutorMiddleware(?compile, ?postCompile, ?plan, ?execute) =
6666
/// An optional pre-existing validation cache can be supplied. If not, one is created and used internally.
6767
type Executor<'Root>(schema: ISchema<'Root>, middlewares : IExecutorMiddleware seq, [<Optional>] validationCache : IValidationResultCache voption) =
6868
let validationCache = validationCache |> ValueOption.defaultWith (fun () -> upcast MemoryValidationResultCache())
69+
70+
// Compute schema ID once and cache it for the lifetime of this Executor instance
71+
let schemaId = SchemaId.fromIntrospectionSchema schema.Introspected
6972

7073
let fieldExecuteMap = FieldExecuteMap(compileField)
7174

@@ -161,7 +164,6 @@ type Executor<'Root>(schema: ISchema<'Root>, middlewares : IExecutorMiddleware s
161164
ErrorKind.Validation
162165
)]
163166
do!
164-
let schemaId = SchemaId.fromIntrospectionSchema schema.Introspected
165167
let key = { DocumentId = documentId; SchemaId = schemaId }
166168
let producer = fun () -> Validation.Ast.validateDocument schema.Introspected ast
167169
validationCache.GetOrAdd producer key

0 commit comments

Comments
 (0)