Skip to content

Commit 1a31994

Browse files
committed
store: Streamline how we get DeploymentDetail a little
1 parent 34b3fca commit 1a31994

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

store/postgres/src/detail.rs

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use diesel::dsl::sql;
66
use diesel::prelude::{
77
ExpressionMethods, JoinOnDsl, NullableExpressionMethods, OptionalExtension, PgConnection,
8-
QueryDsl, RunQueryDsl,
8+
QueryDsl, RunQueryDsl, SelectableHelper as _,
99
};
1010
use diesel_derives::Associations;
1111
use git_testament::{git_testament, git_testament_macros};
@@ -39,26 +39,21 @@ const CARGO_PKG_VERSION_PATCH: &str = env!("CARGO_PKG_VERSION_PATCH");
3939

4040
type Bytes = Vec<u8>;
4141

42-
#[derive(Queryable, QueryableByName)]
42+
#[derive(Queryable, Selectable)]
4343
#[diesel(table_name = subgraph_deployment)]
4444
// We map all fields to make loading `Detail` with diesel easier, but we
4545
// don't need all the fields
46-
#[allow(dead_code)]
4746
pub struct DeploymentDetail {
4847
pub id: DeploymentId,
4948
pub deployment: String,
5049
pub failed: bool,
5150
health: HealthType,
5251
pub synced_at: Option<DateTime<Utc>>,
5352
pub synced_at_block_number: Option<i32>,
54-
fatal_error: Option<String>,
55-
non_fatal_errors: Vec<String>,
5653
/// The earliest block for which we have history
5754
pub earliest_block_number: i32,
5855
pub latest_ethereum_block_hash: Option<Bytes>,
5956
pub latest_ethereum_block_number: Option<BigDecimal>,
60-
last_healthy_ethereum_block_hash: Option<Bytes>,
61-
last_healthy_ethereum_block_number: Option<BigDecimal>,
6257
pub entity_count: BigDecimal,
6358
graft_base: Option<String>,
6459
graft_block_hash: Option<Bytes>,
@@ -67,10 +62,9 @@ pub struct DeploymentDetail {
6762
reorg_count: i32,
6863
current_reorg_depth: i32,
6964
max_reorg_depth: i32,
70-
firehose_cursor: Option<String>,
7165
}
7266

73-
#[derive(Queryable, QueryableByName)]
67+
#[derive(Queryable, Selectable)]
7468
#[diesel(table_name = subgraph_error)]
7569
// We map all fields to make loading `Detail` with diesel easier, but we
7670
// don't need all the fields
@@ -193,16 +187,18 @@ pub(crate) fn info_from_details(
193187
failed: _,
194188
health,
195189
synced_at,
196-
fatal_error: _,
197-
non_fatal_errors: _,
198190
earliest_block_number,
199191
latest_ethereum_block_hash,
200192
latest_ethereum_block_number,
201193
entity_count,
202194
graft_base: _,
203195
graft_block_hash: _,
204196
graft_block_number: _,
205-
..
197+
synced_at_block_number: _,
198+
debug_fork: _,
199+
reorg_count: _,
200+
current_reorg_depth: _,
201+
max_reorg_depth: _,
206202
} = detail;
207203

208204
let site = sites
@@ -261,12 +257,15 @@ pub(crate) fn deployment_details(
261257
) -> Result<Vec<DeploymentDetail>, StoreError> {
262258
use subgraph_deployment as d;
263259

260+
let cols = DeploymentDetail::as_select();
261+
264262
// Empty deployments means 'all of them'
265263
let details = if deployments.is_empty() {
266-
d::table.load::<DeploymentDetail>(conn)?
264+
d::table.select(cols).load::<DeploymentDetail>(conn)?
267265
} else {
268266
d::table
269267
.filter(d::deployment.eq_any(&deployments))
268+
.select(cols)
270269
.load::<DeploymentDetail>(conn)?
271270
};
272271
Ok(details)
@@ -278,8 +277,12 @@ pub(crate) fn deployment_details_for_id(
278277
deployment: &DeploymentId,
279278
) -> Result<DeploymentDetail, StoreError> {
280279
use subgraph_deployment as d;
280+
281+
let cols = DeploymentDetail::as_select();
282+
281283
d::table
282284
.filter(d::id.eq(&deployment))
285+
.select(cols)
283286
.first::<DeploymentDetail>(conn)
284287
.map_err(StoreError::from)
285288
}
@@ -299,15 +302,19 @@ pub(crate) fn deployment_statuses(
299302
let details_with_fatal_error = {
300303
let join = e::table.on(e::id.nullable().eq(d::fatal_error));
301304

305+
let cols = <(DeploymentDetail, Option<ErrorDetail>)>::as_select();
306+
302307
// Empty deployments means 'all of them'
303308
if sites.is_empty() {
304309
d::table
305310
.left_outer_join(join)
311+
.select(cols)
306312
.load::<(DeploymentDetail, Option<ErrorDetail>)>(conn)?
307313
} else {
308314
d::table
309315
.left_outer_join(join)
310316
.filter(d::id.eq_any(sites.iter().map(|site| site.id)))
317+
.select(cols)
311318
.load::<(DeploymentDetail, Option<ErrorDetail>)>(conn)?
312319
}
313320
};
@@ -480,7 +487,8 @@ pub fn deployment_entity(
480487

481488
let detail = d::table
482489
.find(site.id)
483-
.first::<crate::detail::DeploymentDetail>(conn)?;
490+
.select(DeploymentDetail::as_select())
491+
.first::<DeploymentDetail>(conn)?;
484492

485493
StoredDeploymentEntity(detail, manifest).as_subgraph_deployment(schema)
486494
}

0 commit comments

Comments
 (0)