Skip to content

Commit dbbd21c

Browse files
committed
refactor: update cost.rs
Signed-off-by: Gustavo Inacio <[email protected]>
1 parent cba9f41 commit dbbd21c

File tree

1 file changed

+4
-18
lines changed

1 file changed

+4
-18
lines changed

service/src/routes/cost.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::sync::Arc;
77
use async_graphql::{Context, EmptyMutation, EmptySubscription, Object, Schema, SimpleObject};
88
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
99
use axum::extract::State;
10-
use indexer_common::tap::CostModelSource;
1110
use lazy_static::lazy_static;
1211
use prometheus::{
1312
register_counter, register_counter_vec, register_histogram, register_histogram_vec, Counter,
@@ -67,16 +66,6 @@ pub struct GraphQlCostModel {
6766
pub variables: Option<Value>,
6867
}
6968

70-
impl From<CostModel> for CostModelSource {
71-
fn from(value: CostModel) -> Self {
72-
Self {
73-
deployment_id: value.deployment,
74-
model: value.model.unwrap_or_default(),
75-
variables: value.variables.unwrap_or_default().to_string(),
76-
}
77-
}
78-
}
79-
8069
impl From<CostModel> for GraphQlCostModel {
8170
fn from(model: CostModel) -> Self {
8271
Self {
@@ -138,11 +127,8 @@ impl Query {
138127
ctx: &Context<'_>,
139128
deployment_ids: Vec<DeploymentId>,
140129
) -> Result<Vec<GraphQlCostModel>, anyhow::Error> {
141-
let state = &ctx.data_unchecked::<Arc<SubgraphServiceState>>();
142-
143-
let pool = &state.database;
130+
let pool = &ctx.data_unchecked::<Arc<SubgraphServiceState>>().database;
144131
let cost_models = database::cost_models(pool, &deployment_ids).await?;
145-
146132
Ok(cost_models.into_iter().map(|m| m.into()).collect())
147133
}
148134

@@ -152,9 +138,9 @@ impl Query {
152138
deployment_id: DeploymentId,
153139
) -> Result<Option<GraphQlCostModel>, anyhow::Error> {
154140
let pool = &ctx.data_unchecked::<Arc<SubgraphServiceState>>().database;
155-
let model = database::cost_model(pool, &deployment_id).await?;
156-
157-
Ok(model.map(GraphQlCostModel::from))
141+
database::cost_model(pool, &deployment_id)
142+
.await
143+
.map(|model_opt| model_opt.map(GraphQlCostModel::from))
158144
}
159145
}
160146

0 commit comments

Comments
 (0)