Skip to content

Commit 3c04508

Browse files
committed
Have cached landing page use new graph response
1 parent aedbd1b commit 3c04508

File tree

2 files changed

+29
-28
lines changed

2 files changed

+29
-28
lines changed

site/src/load.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct SiteCtxt {
7979
/// Site configuration
8080
pub config: Config,
8181
/// Cached site landing page
82-
pub landing_page: ArcSwap<Option<Arc<crate::api::graph::Response>>>,
82+
pub landing_page: ArcSwap<Option<Arc<crate::api::graph::NewResponse>>>,
8383
/// Index of various common queries
8484
pub index: ArcSwap<crate::db::Index>,
8585
/// Database connection pool

site/src/request_handlers/graph.rs

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,24 @@ use crate::selector::{self, PathComponent, Tag};
1515
pub async fn handle_graph(
1616
body: graph::Request,
1717
ctxt: &SiteCtxt,
18-
) -> ServerResult<graph::NewResponse> {
18+
) -> ServerResult<Arc<graph::NewResponse>> {
1919
log::info!("handle_graph({:?})", body);
20+
21+
let is_default_query = body
22+
== graph::Request {
23+
start: Bound::None,
24+
end: Bound::None,
25+
stat: String::from("instructions:u"),
26+
kind: graph::GraphKind::Raw,
27+
};
28+
29+
if is_default_query {
30+
match &**ctxt.landing_page.load() {
31+
Some(resp) => return Ok(resp.clone()),
32+
None => {}
33+
}
34+
}
35+
2036
let range = ctxt.data_range(body.start.clone()..=body.end.clone());
2137
let commits: Vec<ArtifactId> = range.iter().map(|c| c.clone().into()).collect();
2238

@@ -52,7 +68,7 @@ pub async fn handle_graph(
5268
benchmarks.insert(benchmark_.clone(), by_profile);
5369
}
5470

55-
Ok(graph::NewResponse {
71+
let resp = Arc::new(graph::NewResponse {
5672
commits: commits
5773
.into_iter()
5874
.map(|c| match c {
@@ -61,30 +77,21 @@ pub async fn handle_graph(
6177
})
6278
.collect(),
6379
benchmarks,
64-
})
80+
});
81+
82+
if is_default_query {
83+
ctxt.landing_page.store(Arc::new(Some(resp.clone())));
84+
}
85+
86+
Ok(resp)
6587
}
6688

6789
static INTERPOLATED_COLOR: &str = "#fcb0f1";
6890

6991
async fn handle_graph_impl(
7092
body: graph::Request,
7193
ctxt: &SiteCtxt,
72-
) -> ServerResult<Arc<graph::Response>> {
73-
let is_default_query = body
74-
== graph::Request {
75-
start: Bound::None,
76-
end: Bound::None,
77-
stat: String::from("instructions:u"),
78-
kind: graph::GraphKind::Raw,
79-
};
80-
81-
if is_default_query {
82-
match &**ctxt.landing_page.load() {
83-
Some(resp) => return Ok(resp.clone()),
84-
None => {}
85-
}
86-
}
87-
94+
) -> ServerResult<graph::Response> {
8895
let cc = CommitIdxCache::new();
8996
let range = ctxt.data_range(body.start.clone()..=body.end.clone());
9097
let commits: Arc<Vec<_>> = Arc::new(range.iter().map(|c| c.clone().into()).collect());
@@ -215,18 +222,12 @@ async fn handle_graph_impl(
215222
.push((sr.path.get::<Scenario>()?.to_string(), sr.series));
216223
}
217224

218-
let resp = Arc::new(graph::Response {
225+
Ok(graph::Response {
219226
max: by_benchmark_max,
220227
benchmarks: by_test_case,
221228
colors: vec![String::new(), String::from(INTERPOLATED_COLOR)],
222229
commits: cc.into_commits(),
223-
});
224-
225-
if is_default_query {
226-
ctxt.landing_page.store(Arc::new(Some(resp.clone())));
227-
}
228-
229-
Ok(resp)
230+
})
230231
}
231232

232233
struct CommitIdxCache {

0 commit comments

Comments
 (0)