Skip to content

Commit 43c04b7

Browse files
Copilotxperiandri
andauthored
Change validation SchemaId type to int
Agent-Logs-Url: https://github.com/fsprojects/FSharp.Data.GraphQL/sessions/50df7657-a96d-4b4f-89a9-b012c920b492 Co-authored-by: xperiandri <2365592+xperiandri@users.noreply.github.com>
1 parent 7291234 commit 43c04b7

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

src/FSharp.Data.GraphQL.Shared/ValidationResultCache.fs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ open System
66

77
type ValidationResultKey =
88
{ DocumentId : string
9-
SchemaId : string }
9+
SchemaId : int }
1010

1111
type ValidationResultProducer =
1212
unit -> ValidationResult<GQLProblemDetails>
@@ -20,10 +20,10 @@ module SchemaId =
2020
/// This identifier is valid only within the current process/runtime and is not deterministic across process restarts.
2121
/// </summary>
2222
/// <param name="introspectionSchema">The introspection schema.</param>
23-
/// <returns>A string representation of the schema hash code for in-process cache keys.</returns>
23+
/// <returns>The schema hash code for in-process cache keys.</returns>
2424
[<CompiledName("FromIntrospectionSchema")>]
2525
let fromIntrospectionSchema (introspectionSchema : IntrospectionSchema) =
26-
introspectionSchema.GetHashCode().ToString(System.Globalization.CultureInfo.InvariantCulture)
26+
introspectionSchema.GetHashCode()
2727

2828
/// An in-memory cache for the results of schema/document validations, with a lifetime of 30 seconds.
2929
type MemoryValidationResultCache () =

tests/FSharp.Data.GraphQL.Tests/ValidationCacheTests.fs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let ``MemoryValidationResultCache caches results for same key`` () =
1616
Interlocked.Increment(&callCount) |> ignore
1717
Success
1818

19-
let key = { DocumentId = "doc1"; SchemaId = "schema1" }
19+
let key = { DocumentId = "doc1"; SchemaId = 1 }
2020

2121
// First call should invoke producer
2222
let result1 = cache.GetOrAdd producer key
@@ -36,8 +36,8 @@ let ``MemoryValidationResultCache uses different cache entries for different Doc
3636
Interlocked.Increment(&callCount) |> ignore
3737
Success
3838

39-
let key1 = { DocumentId = "doc1"; SchemaId = "schema1" }
40-
let key2 = { DocumentId = "doc2"; SchemaId = "schema1" }
39+
let key1 = { DocumentId = "doc1"; SchemaId = 1 }
40+
let key2 = { DocumentId = "doc2"; SchemaId = 1 }
4141

4242
// First call
4343
let result1 = cache.GetOrAdd producer key1
@@ -55,8 +55,8 @@ let ``MemoryValidationResultCache uses different cache entries for different Sch
5555
Interlocked.Increment(&callCount) |> ignore
5656
Success
5757

58-
let key1 = { DocumentId = "doc1"; SchemaId = "schema1" }
59-
let key2 = { DocumentId = "doc1"; SchemaId = "schema2" }
58+
let key1 = { DocumentId = "doc1"; SchemaId = 1 }
59+
let key2 = { DocumentId = "doc1"; SchemaId = 2 }
6060

6161
// First call
6262
let result1 = cache.GetOrAdd producer key1
@@ -72,8 +72,8 @@ let ``MemoryValidationResultCache distinguishes keys with same hash code`` () =
7272

7373
// Create two different keys that might have hash collisions
7474
// Using very similar but different strings
75-
let key1 = { DocumentId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; SchemaId = "schema1" }
76-
let key2 = { DocumentId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; SchemaId = "schema1" }
75+
let key1 = { DocumentId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; SchemaId = 1 }
76+
let key2 = { DocumentId = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaab"; SchemaId = 1 }
7777

7878
let mutable callCount = 0
7979
let producer () =
@@ -97,7 +97,7 @@ let ``MemoryValidationResultCache caches error results`` () =
9797
Interlocked.Increment(&callCount) |> ignore
9898
ValidationError [error]
9999

100-
let key = { DocumentId = "doc1"; SchemaId = "schema1" }
100+
let key = { DocumentId = "doc1"; SchemaId = 1 }
101101

102102
// First call should invoke producer
103103
let result1 = cache.GetOrAdd producer key
@@ -122,7 +122,7 @@ let ``MemoryValidationResultCache handles concurrent access`` () =
122122
Thread.Sleep(10) // Simulate some work
123123
Success
124124

125-
let key = { DocumentId = "doc1"; SchemaId = "schema1" }
125+
let key = { DocumentId = "doc1"; SchemaId = 1 }
126126

127127
// Call cache from multiple threads simultaneously
128128
let tasks =

0 commit comments

Comments
 (0)