Skip to content

Commit 883ebf5

Browse files
committed
graphql: Log cached status of queries
1 parent 55cdf63 commit 883ebf5

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

graphql/src/execution/execution.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use stable_hash::prelude::*;
77
use stable_hash::utils::stable_hash;
88
use std::collections::{BTreeMap, HashMap, HashSet};
99
use std::iter;
10+
use std::sync::atomic::AtomicBool;
1011
use std::time::Instant;
1112

1213
use graph::prelude::*;
@@ -128,6 +129,9 @@ where
128129

129130
/// Max value for `first`.
130131
pub max_first: u32,
132+
133+
/// Set to `true` if the response was cached. Used for logging.
134+
pub cached: AtomicBool,
131135
}
132136

133137
// Helpers to look for types and fields on both the introspection and regular schemas.
@@ -164,6 +168,7 @@ where
164168
query: self.query.as_introspection_query(),
165169
deadline: self.deadline,
166170
max_first: std::u32::MAX,
171+
cached: AtomicBool::new(false),
167172
}
168173
}
169174
}
@@ -190,6 +195,7 @@ pub fn execute_root_selection_set(
190195

191196
// Peek because we want even hot entries to invalidate after the expiry period.
192197
if let Some(response) = cache.peek(key.as_ref().unwrap()) {
198+
ctx.cached.store(true, std::sync::atomic::Ordering::SeqCst);
193199
return Ok(response.clone());
194200
}
195201
}

graphql/src/query/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use graph::prelude::{info, o, Logger, QueryExecutionError};
22
use graphql_parser::query as q;
33
use std::collections::BTreeMap;
4-
use std::sync::Arc;
4+
use std::sync::{atomic::AtomicBool, Arc};
55
use std::time::Instant;
66
use uuid::Uuid;
77

@@ -54,6 +54,7 @@ where
5454
query: query.clone(),
5555
deadline: options.deadline,
5656
max_first: options.max_first,
57+
cached: AtomicBool::new(false),
5758
};
5859

5960
if !query.is_query() {
@@ -79,6 +80,7 @@ where
7980
"query" => &query.query_text,
8081
"variables" => &query.variables_text,
8182
"query_time_ms" => start.elapsed().as_millis(),
83+
"cached" => ctx.cached.load(std::sync::atomic::Ordering::SeqCst),
8284
);
8385
}
8486
result

graphql/src/subscription/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use graphql_parser::{query as q, schema as s};
22
use std::collections::HashMap;
33
use std::iter;
44
use std::result::Result;
5-
use std::sync::Arc;
5+
use std::sync::{atomic::AtomicBool, Arc};
66
use std::time::{Duration, Instant};
77

88
use graph::prelude::*;
@@ -82,6 +82,7 @@ where
8282
query: query.clone(),
8383
deadline: None,
8484
max_first: options.max_first,
85+
cached: AtomicBool::new(false),
8586
};
8687

8788
if !query.is_subscription() {
@@ -197,6 +198,7 @@ async fn execute_subscription_event(
197198
query,
198199
deadline: timeout.map(|t| Instant::now() + t),
199200
max_first,
201+
cached: AtomicBool::new(false),
200202
};
201203

202204
// We have established that this exists earlier in the subscription execution

0 commit comments

Comments
 (0)