fn reconcile_assignments(
        &self,
        logger: &Logger,
        versions_before: Vec<SubgraphVersionSummary>,
        versions_after: Vec<SubgraphVersionSummary>,
        node_id: Option<NodeId>,
    ) -> Vec<EntityOperation> {
        fn should_have_assignment(version: &SubgraphVersionSummary) -> bool {
            version.pending || version.current
        }

        let assignments_before = versions_before
            .into_iter()
            .filter(should_have_assignment)
            .map(|v| v.deployment_id)
            .collect::<HashSet<_>>();
        let assignments_after = versions_after
            .into_iter()
            .filter(should_have_assignment)
            .map(|v| v.deployment_id)
            .collect::<HashSet<_>>();
        let removed_assignments = &assignments_before - &assignments_after;
        let added_assignments = &assignments_after - &assignments_before;

        let mut ops = vec![];

        if !removed_assignments.is_empty() {
            debug!(
                logger,
                "Removing subgraph node assignments for {} subgraph deployment ID(s) ({})",
                removed_assignments.len(),
                removed_assignments
                    .iter()
                    .map(ToString::to_string)
                    .collect::<Vec<_>>()
                    .join(", ")
            );
        }
        if !added_assignments.is_empty() {
            debug!(
                logger,
                "Adding subgraph node assignments for {} subgraph deployment ID(s) ({})",
                added_assignments.len(),
                added_assignments
                    .iter()
                    .map(ToString::to_string)
                    .collect::<Vec<_>>()
                    .join(", ")
            );
        }

        ops.extend(
            removed_assignments
                .into_iter()
                .map(|deployment_id| EntityOperation::Remove {
                    key: SubgraphDeploymentAssignmentEntity::key(deployment_id),
                }),
        );
        ops.extend(added_assignments.iter().flat_map(|deployment_id| {
            SubgraphDeploymentAssignmentEntity::new(
                node_id
                    .clone()
                    .expect("Cannot create new subgraph deployment assignment without node ID"),
            )
            .write_operations(deployment_id)
        }));

        ops
    }
/// Produce the EntityOperations needed to create/remove
/// SubgraphDeploymentAssignments to reflect the addition/removal of
/// SubgraphVersions between `versions_before` and `versions_after`.
/// Any new assignments are created with the specified `node_id`.
/// `node_id` can be `None` if it is known that no versions were added.
Produce the EntityOperations needed to create/remove
SubgraphDeploymentAssignments to reflect the addition/removal of
SubgraphVersions between `versions_before` and `versions_after`.
Any new assignments are created with the specified `node_id`.
`node_id` can be `None` if it is known that no versions were added.
Produce the EntityOperations needed to create / remove SubgraphDeploymentAssignments to reflect the addition / removal of SubgraphVersions between ` versions_before ` and ` versions_after ` . Any new assignments are created with the specified ` node_id ` . ` node_id ` can be ` None ` if it is known that no versions were added .
fn reconcile_assignments(
        &self,
        logger: &Logger,
        versions_before: Vec<SubgraphVersionSummary>,
        versions_after: Vec<SubgraphVersionSummary>,
        node_id: Option<NodeId>,
    ) -> Vec<EntityOperation> {
        fn should_have_assignment(version: &SubgraphVersionSummary) -> bool {
            version.pending || version.current
        }
        let assignments_before = versions_before
            .into_iter()
            .filter(should_have_assignment)
            .map(|v| v.deployment_id)
            .collect::<HashSet<_>>();
        let assignments_after = versions_after
            .into_iter()
            .filter(should_have_assignment)
            .map(|v| v.deployment_id)
            .collect::<HashSet<_>>();
        let removed_assignments = &assignments_before - &assignments_after;
        let added_assignments = &assignments_after - &assignments_before;
        let mut ops = vec![];
        if !removed_assignments.is_empty() {
            debug!(
                logger,
                "Removing subgraph node assignments for {} subgraph deployment ID(s) ({})",
                removed_assignments.len(),
                removed_assignments
                    .iter()
                    .map(ToString::to_string)
                    .collect::<Vec<_>>()
                    .join(", ")
            );
        }
        if !added_assignments.is_empty() {
            debug!(
                logger,
                "Adding subgraph node assignments for {} subgraph deployment ID(s) ({})",
                added_assignments.len(),
                added_assignments
                    .iter()
                    .map(ToString::to_string)
                    .collect::<Vec<_>>()
                    .join(", ")
            );
        }
        ops.extend(
            removed_assignments
                .into_iter()
                .map(|deployment_id| EntityOperation::Remove {
                    key: SubgraphDeploymentAssignmentEntity::key(deployment_id),
                }),
        );
        ops.extend(added_assignments.iter().flat_map(|deployment_id| {
            SubgraphDeploymentAssignmentEntity::new(
                node_id
                    .clone()
                    .expect("Cannot create new subgraph deployment assignment without node ID"),
            )
            .write_operations(deployment_id)
        }));
        ops
    }
fn reconcile_assignments ( & self , logger : & Logger , versions_before : Vec < SubgraphVersionSummary > , versions_after : Vec < SubgraphVersionSummary > , node_id : Option < NodeId > , ) -> Vec < EntityOperation > { fn should_have_assignment ( version : & SubgraphVersionSummary ) -> bool { version . pending || version . current } let assignments_before = versions_before . into_iter ( ) . filter ( should_have_assignment ) . map ( | v | v . deployment_id ) . collect :: < HashSet < _ > > ( ) ; let assignments_after = versions_after . into_iter ( ) . filter ( should_have_assignment ) . map ( | v | v . deployment_id ) . collect :: < HashSet < _ > > ( ) ; let removed_assignments = & assignments_before - & assignments_after ; let added_assignments = & assignments_after - & assignments_before ; let mut ops = vec ! [ ] ; if ! removed_assignments . is_empty ( ) { debug ! ( logger " " removed_assignments len ( ) removed_assignments iter ( ) map ( ToString to_string ) collect Vec ( ) join ( " " ) ) ; } if ! added_assignments . is_empty ( ) { debug ! ( logger " " added_assignments len ( ) added_assignments iter ( ) map ( ToString to_string ) collect Vec ( ) join ( " " ) ) ; } ops . extend ( removed_assignments . into_iter ( ) . map ( | deployment_id | EntityOperation :: Remove { key : SubgraphDeploymentAssignmentEntity :: key ( deployment_id ) , } ) , ) ; ops . extend ( added_assignments . iter ( ) . flat_map ( | deployment_id | { SubgraphDeploymentAssignmentEntity :: new ( node_id . clone ( ) . expect ( " " ) , ) . write_operations ( deployment_id ) } ) ) ; ops }
Produce the EntityOperations needed to create/remove
SubgraphDeploymentAssignments to reflect the addition/removal of
SubgraphVersions between `versions_before` and `versions_after`.
Produce the EntityOperations needed to create / remove SubgraphDeploymentAssignments to reflect the addition / removal of SubgraphVersions between ` versions_before ` and ` versions_after ` .
&self
logger
&Logger
versions_before
Vec<SubgraphVersionSummary>
versions_after
Vec<SubgraphVersionSummary>
node_id
Option<NodeId>
&self
logger
&Logger
versions_before
Vec<SubgraphVersionSummary>
versions_after
Vec<SubgraphVersionSummary>
node_id
Option<NodeId>