@@ -299,13 +299,11 @@ where
299299
300300 fn reassign_subgraph (
301301 & self ,
302- name : SubgraphName ,
303302 hash : SubgraphDeploymentId ,
304303 node_id : NodeId ,
305304 ) -> Box < Future < Item = ( ) , Error = SubgraphRegistrarError > + Send + ' static > {
306305 Box :: new ( future:: result ( reassign_subgraph (
307306 self . store . clone ( ) ,
308- name,
309307 hash,
310308 node_id,
311309 ) ) )
@@ -849,36 +847,34 @@ fn remove_subgraph_versions(
849847/// subgraph syncing process.
850848fn reassign_subgraph (
851849 store : Arc < impl Store > ,
852- name : SubgraphName ,
853850 hash : SubgraphDeploymentId ,
854851 node_id : NodeId ,
855852) -> Result < ( ) , SubgraphRegistrarError > {
856853 let mut ops = vec ! [ ] ;
857854
858- // Find all subgraph version entities that point to this hash.
859- let ( version_summaries , read_summaries_abort_ops ) =
860- store . read_subgraph_version_summaries ( vec ! [ hash. clone( ) ] ) ? ;
861- ops . extend ( read_summaries_abort_ops ) ;
855+ let current_deployment = store . find (
856+ SubgraphDeploymentAssignmentEntity :: query ( )
857+ . filter ( EntityFilter :: new_equal ( "id" , hash. clone ( ) . to_string ( ) ) ) ,
858+ ) ? ;
862859
863- ops. push ( EntityOperation :: AbortUnless {
864- description : "Provided name-deploymentId pair must match an existing subgraph version"
865- . to_owned ( ) ,
866- query : SubgraphEntity :: query ( )
867- . filter ( EntityFilter :: new_in ( "name" , vec ! [ name. clone( ) . to_string( ) ] ) ) ,
868- entity_ids : version_summaries
869- . iter ( )
870- . filter ( |version| version. deployment_id == hash)
871- . map ( move |summary| summary. clone ( ) . subgraph_id )
872- . collect ( ) ,
873- } ) ;
860+ let current_node_id = current_deployment
861+ . first ( )
862+ . and_then ( |d| d. get ( "nodeId" ) )
863+ . ok_or_else ( || SubgraphRegistrarError :: DeploymentNotFound ( hash. clone ( ) . to_string ( ) ) ) ?;
864+
865+ if current_node_id. to_string ( ) == node_id. to_string ( ) {
866+ return Err ( SubgraphRegistrarError :: DeploymentAssignmentUnchanged (
867+ hash. clone ( ) . to_string ( ) ,
868+ ) ) ;
869+ }
874870
875871 ops. push ( EntityOperation :: AbortUnless {
876- description : "Target node must be different from the currently assigned one " . to_owned ( ) ,
872+ description : "Deployment assignment is unchanged " . to_owned ( ) ,
877873 query : SubgraphDeploymentAssignmentEntity :: query ( ) . filter ( EntityFilter :: And ( vec ! [
878- EntityFilter :: new_equal( "nodeId" , node_id . to_string( ) ) ,
874+ EntityFilter :: new_equal( "nodeId" , current_node_id . to_string( ) ) ,
879875 EntityFilter :: new_equal( "id" , hash. clone( ) . to_string( ) ) ,
880876 ] ) ) ,
881- entity_ids : vec ! [ ] ,
877+ entity_ids : vec ! [ hash . clone ( ) . to_string ( ) ] ,
882878 } ) ;
883879
884880 // Create the assignment update operations.
0 commit comments