File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use stable_hash::prelude::*;
7
7
use stable_hash:: utils:: stable_hash;
8
8
use std:: collections:: { BTreeMap , HashMap , HashSet } ;
9
9
use std:: iter;
10
+ use std:: sync:: atomic:: AtomicBool ;
10
11
use std:: time:: Instant ;
11
12
12
13
use graph:: prelude:: * ;
@@ -128,6 +129,9 @@ where
128
129
129
130
/// Max value for `first`.
130
131
pub max_first : u32 ,
132
+
133
+ /// Set to `true` if the response was cached. Used for logging.
134
+ pub cached : AtomicBool ,
131
135
}
132
136
133
137
// Helpers to look for types and fields on both the introspection and regular schemas.
@@ -164,6 +168,7 @@ where
164
168
query : self . query . as_introspection_query ( ) ,
165
169
deadline : self . deadline ,
166
170
max_first : std:: u32:: MAX ,
171
+ cached : AtomicBool :: new ( false ) ,
167
172
}
168
173
}
169
174
}
@@ -190,6 +195,7 @@ pub fn execute_root_selection_set(
190
195
191
196
// Peek because we want even hot entries to invalidate after the expiry period.
192
197
if let Some ( response) = cache. peek ( key. as_ref ( ) . unwrap ( ) ) {
198
+ ctx. cached . store ( true , std:: sync:: atomic:: Ordering :: SeqCst ) ;
193
199
return Ok ( response. clone ( ) ) ;
194
200
}
195
201
}
Original file line number Diff line number Diff line change 1
1
use graph:: prelude:: { info, o, Logger , QueryExecutionError } ;
2
2
use graphql_parser:: query as q;
3
3
use std:: collections:: BTreeMap ;
4
- use std:: sync:: Arc ;
4
+ use std:: sync:: { atomic :: AtomicBool , Arc } ;
5
5
use std:: time:: Instant ;
6
6
use uuid:: Uuid ;
7
7
54
54
query : query. clone ( ) ,
55
55
deadline : options. deadline ,
56
56
max_first : options. max_first ,
57
+ cached : AtomicBool :: new ( false ) ,
57
58
} ;
58
59
59
60
if !query. is_query ( ) {
79
80
"query" => & query. query_text,
80
81
"variables" => & query. variables_text,
81
82
"query_time_ms" => start. elapsed( ) . as_millis( ) ,
83
+ "cached" => ctx. cached. load( std:: sync:: atomic:: Ordering :: SeqCst ) ,
82
84
) ;
83
85
}
84
86
result
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ use graphql_parser::{query as q, schema as s};
2
2
use std:: collections:: HashMap ;
3
3
use std:: iter;
4
4
use std:: result:: Result ;
5
- use std:: sync:: Arc ;
5
+ use std:: sync:: { atomic :: AtomicBool , Arc } ;
6
6
use std:: time:: { Duration , Instant } ;
7
7
8
8
use graph:: prelude:: * ;
82
82
query : query. clone ( ) ,
83
83
deadline : None ,
84
84
max_first : options. max_first ,
85
+ cached : AtomicBool :: new ( false ) ,
85
86
} ;
86
87
87
88
if !query. is_subscription ( ) {
@@ -197,6 +198,7 @@ async fn execute_subscription_event(
197
198
query,
198
199
deadline : timeout. map ( |t| Instant :: now ( ) + t) ,
199
200
max_first,
201
+ cached : AtomicBool :: new ( false ) ,
200
202
} ;
201
203
202
204
// We have established that this exists earlier in the subscription execution
You can’t perform that action at this time.
0 commit comments