Skip to content

Commit a10ac6d

Browse files
committed
graph, store: 'graphman info': Do not get confused by copies
Because the code in primary::queries::fill_assignments used the deployment hash to reference a deployment, it would get confused by copies since for those several deployments have the same hash
1 parent 2f365c3 commit a10ac6d

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

graph/src/components/store/mod.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ mod err;
33
mod traits;
44
pub mod write;
55

6+
use diesel::deserialize::FromSql;
7+
use diesel::pg::Pg;
8+
use diesel::serialize::{Output, ToSql};
9+
use diesel::sql_types::Integer;
10+
use diesel_derives::{AsExpression, FromSqlRow};
611
pub use entity_cache::{EntityCache, EntityLfuCache, GetScope, ModificationsAndCache};
712
use slog::Logger;
813

@@ -691,7 +696,20 @@ pub struct StoredDynamicDataSource {
691696
/// identifier only has meaning in the context of a specific instance of
692697
/// graph-node. Only store code should ever construct or consume it; all
693698
/// other code passes it around as an opaque token.
694-
#[derive(Copy, Clone, CheapClone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
699+
#[derive(
700+
Copy,
701+
Clone,
702+
CheapClone,
703+
Debug,
704+
Serialize,
705+
Deserialize,
706+
PartialEq,
707+
Eq,
708+
Hash,
709+
AsExpression,
710+
FromSqlRow,
711+
)]
712+
#[diesel(sql_type = Integer)]
695713
pub struct DeploymentId(pub i32);
696714

697715
impl Display for DeploymentId {
@@ -706,6 +724,19 @@ impl DeploymentId {
706724
}
707725
}
708726

727+
impl FromSql<Integer, Pg> for DeploymentId {
728+
fn from_sql(bytes: diesel::pg::PgValue) -> diesel::deserialize::Result<Self> {
729+
let id = <i32 as FromSql<Integer, Pg>>::from_sql(bytes)?;
730+
Ok(DeploymentId(id))
731+
}
732+
}
733+
734+
impl ToSql<Integer, Pg> for DeploymentId {
735+
fn to_sql<'b>(&'b self, out: &mut Output<'b, '_, Pg>) -> diesel::serialize::Result {
736+
<i32 as ToSql<Integer, Pg>>::to_sql(&self.0, out)
737+
}
738+
}
739+
709740
/// A unique identifier for a deployment that specifies both its external
710741
/// identifier (`hash`) and its unique internal identifier (`id`) which
711742
/// ensures we are talking about a unique location for the deployment's data

store/postgres/src/primary.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,7 @@ mod queries {
450450
use diesel::sql_types::Text;
451451
use graph::prelude::NodeId;
452452
use graph::{
453+
components::store::DeploymentId as GraphDeploymentId,
453454
data::subgraph::status,
454455
internal_error,
455456
prelude::{DeploymentHash, StoreError, SubgraphName},
@@ -646,18 +647,18 @@ mod queries {
646647
conn: &mut PgConnection,
647648
infos: &mut [status::Info],
648649
) -> Result<(), StoreError> {
649-
let ids: Vec<_> = infos.iter().map(|info| &info.subgraph).collect();
650+
let ids: Vec<_> = infos.iter().map(|info| &info.id).collect();
650651
let nodes: HashMap<_, _> = a::table
651652
.inner_join(ds::table.on(ds::id.eq(a::id)))
652-
.filter(ds::subgraph.eq_any(ids))
653-
.select((ds::subgraph, a::node_id, a::paused_at.is_not_null()))
654-
.load::<(String, String, bool)>(conn)?
653+
.filter(ds::id.eq_any(ids))
654+
.select((ds::id, a::node_id, a::paused_at.is_not_null()))
655+
.load::<(GraphDeploymentId, String, bool)>(conn)?
655656
.into_iter()
656-
.map(|(subgraph, node, paused)| (subgraph, (node, paused)))
657+
.map(|(id, node, paused)| (id, (node, paused)))
657658
.collect();
658659
for info in infos {
659-
info.node = nodes.get(&info.subgraph).map(|(node, _)| node.clone());
660-
info.paused = nodes.get(&info.subgraph).map(|(_, paused)| *paused);
660+
info.node = nodes.get(&info.id).map(|(node, _)| node.clone());
661+
info.paused = nodes.get(&info.id).map(|(_, paused)| *paused);
661662
}
662663
Ok(())
663664
}

0 commit comments

Comments
 (0)