Skip to content

Commit 33d2f97

Browse files
committed
graph, store - expose history_blocks in index-node API
1 parent 765e683 commit 33d2f97

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

graph/src/data/subgraph/status.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ pub struct Info {
111111

112112
/// ID of the Graph Node that the subgraph is indexed by.
113113
pub node: Option<String>,
114+
115+
pub history_blocks: i32,
114116
}
115117

116118
impl IntoValue for Info {
@@ -125,6 +127,7 @@ impl IntoValue for Info {
125127
node,
126128
non_fatal_errors,
127129
synced,
130+
history_blocks,
128131
} = self;
129132

130133
fn subgraph_error_to_value(subgraph_error: SubgraphError) -> r::Value {
@@ -166,6 +169,7 @@ impl IntoValue for Info {
166169
chains: chains.into_iter().map(|chain| chain.into_value()).collect::<Vec<_>>(),
167170
entityCount: format!("{}", entity_count),
168171
node: node,
172+
historyBlocks: history_blocks,
169173
}
170174
}
171175
}

server/index-node/src/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ type SubgraphIndexingStatus {
6565
chains: [ChainIndexingStatus!]!
6666
entityCount: BigInt!
6767
node: String
68+
historyBlocks: Int!
6869
}
6970

7071
interface ChainIndexingStatus {

store/postgres/src/detail.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use graph::prelude::{
1818
};
1919
use graph::{constraint_violation, data::subgraph::status, prelude::web3::types::H256};
2020
use itertools::Itertools;
21+
use std::collections::HashMap;
2122
use std::convert::TryFrom;
2223
use std::{ops::Bound, sync::Arc};
2324

@@ -182,6 +183,7 @@ pub(crate) fn info_from_details(
182183
fatal: Option<ErrorDetail>,
183184
non_fatal: Vec<ErrorDetail>,
184185
sites: &[Arc<Site>],
186+
subgraph_history_blocks: i32,
185187
) -> Result<status::Info, StoreError> {
186188
let DeploymentDetail {
187189
id,
@@ -245,6 +247,7 @@ pub(crate) fn info_from_details(
245247
chains: vec![chain],
246248
entity_count,
247249
node: None,
250+
history_blocks: subgraph_history_blocks,
248251
})
249252
}
250253

@@ -272,6 +275,7 @@ pub(crate) fn deployment_statuses(
272275
) -> Result<Vec<status::Info>, StoreError> {
273276
use subgraph_deployment as d;
274277
use subgraph_error as e;
278+
use subgraph_manifest as sm;
275279

276280
// First, we fetch all deployment information along with any fatal errors.
277281
// Subsequently, we fetch non-fatal errors and we group them by deployment
@@ -312,11 +316,27 @@ pub(crate) fn deployment_statuses(
312316
.into_group_map()
313317
};
314318

319+
let mut history_blocks_map: HashMap<_, _> = {
320+
if sites.is_empty() {
321+
sm::table
322+
.select((sm::id, sm::history_blocks))
323+
.load::<(DeploymentId, i32)>(conn)?
324+
} else {
325+
sm::table
326+
.filter(sm::id.eq_any(sites.iter().map(|site| site.id)))
327+
.select((sm::id, sm::history_blocks))
328+
.load::<(DeploymentId, i32)>(conn)?
329+
}
330+
.into_iter()
331+
.collect()
332+
};
333+
315334
details_with_fatal_error
316335
.into_iter()
317336
.map(|(detail, fatal)| {
318337
let non_fatal = non_fatal_errors.remove(&detail.id).unwrap_or_default();
319-
info_from_details(detail, fatal, non_fatal, sites)
338+
let subgraph_history_blocks = history_blocks_map.remove(&detail.id).unwrap_or_default();
339+
info_from_details(detail, fatal, non_fatal, sites, subgraph_history_blocks)
320340
})
321341
.collect()
322342
}

0 commit comments

Comments
 (0)