Update get_node to be wrapped in transaction for atomicity
@@ -39,6 +39,7 @@ where
String: diesel::deserialize::FromSql<diesel::sql_types::Text, C::Backend>,
{
fn get_node(&self, identity: &str) -> Result<Option<Node>, RegistryError> {
+ self.conn.transaction(|| {
let node = splinter_nodes::table
.find(identity)
.first::<NodesModel>(self.conn)
@@ -69,10 +70,13 @@ where
builder = builder.with_metadata(entry.key, entry.value);
}
Ok(Some(builder.build().map_err(|err| {
- RegistryError::InvalidStateError(InvalidStateError::with_message(err.to_string()))
+ RegistryError::InvalidStateError(InvalidStateError::with_message(
+ err.to_string(),
+ ))
})?))
} else {
Ok(None)
}
+ })
}
}
