fn remove_subgraph_versions(
    logger: &Logger,
    store: Arc<impl Store>,
    version_entities_to_delete: Vec<Entity>,
) -> Result<Vec<EntityOperation>, SubgraphRegistrarError> {
    let mut ops = vec![];

    let version_entity_ids_to_delete = version_entities_to_delete
        .iter()
        .map(|version_entity| version_entity.id().unwrap())
        .collect::<HashSet<_>>();

    // Get hashes that are referenced by versions that will be deleted.
    // These are candidates for clean up.
    let referenced_subgraph_hashes = version_entities_to_delete
        .iter()
        .map(|version_entity| {
            SubgraphDeploymentId::new(
                version_entity
                    .get("deployment")
                    .unwrap()
                    .to_owned()
                    .as_string()
                    .unwrap(),
            )
            .unwrap()
        })
        .collect::<HashSet<_>>();

    // Find all subgraph version entities that point to these subgraph deployments
    let (version_summaries, read_summaries_ops) =
        store.read_subgraph_version_summaries(referenced_subgraph_hashes.into_iter().collect())?;
    ops.extend(read_summaries_ops);

    // Simulate the planned removal of SubgraphVersion entities
    let version_summaries_after_delete = version_summaries
        .clone()
        .into_iter()
        .filter(|version_summary| !version_entity_ids_to_delete.contains(&version_summary.id))
        .collect::<Vec<_>>();

    // Create/remove assignments based on the subgraph version changes.
    // We are only deleting versions here, so no assignments will be created,
    // and we can safely pass None for the node ID.
    ops.extend(store.reconcile_assignments(
        logger,
        version_summaries,
        version_summaries_after_delete,
        None,
    ));

    // Actually remove the subgraph version entities.
    // Note: we do this last because earlier AbortUnless ops depend on these entities still
    // existing.
    ops.extend(
        version_entities_to_delete
            .iter()
            .map(|version_entity| EntityOperation::Remove {
                key: SubgraphVersionEntity::key(version_entity.id().unwrap()),
            }),
    );

    Ok(ops)
}
/// Remove a set of subgraph versions atomically.
///
/// It may seem like it would be easier to generate the EntityOperations for subgraph versions
/// removal one at a time, but that approach is significantly complicated by the fact that the
/// store does not reflect the EntityOperations that have been accumulated so far. Earlier subgraph
/// version creations/removals can affect later ones by affecting whether or not a subgraph deployment
/// or assignment needs to be created/removed.
Remove a set of subgraph versions atomically.
It may seem like it would be easier to generate the EntityOperations for subgraph versions
removal one at a time, but that approach is significantly complicated by the fact that the
store does not reflect the EntityOperations that have been accumulated so far. Earlier subgraph
version creations/removals can affect later ones by affecting whether or not a subgraph deployment
or assignment needs to be created/removed.
Remove a set of subgraph versions atomically . It may seem like it would be easier to generate the EntityOperations for subgraph versions removal one at a time but that approach is significantly complicated by the fact that the store does not reflect the EntityOperations that have been accumulated so far . Earlier subgraph version creations / removals can affect later ones by affecting whether or not a subgraph deployment or assignment needs to be created / removed .
fn remove_subgraph_versions(
    logger: &Logger,
    store: Arc<impl Store>,
    version_entities_to_delete: Vec<Entity>,
) -> Result<Vec<EntityOperation>, SubgraphRegistrarError> {
    let mut ops = vec![];
    let version_entity_ids_to_delete = version_entities_to_delete
        .iter()
        .map(|version_entity| version_entity.id().unwrap())
        .collect::<HashSet<_>>();
    // Get hashes that are referenced by versions that will be deleted.
    // These are candidates for clean up.
    let referenced_subgraph_hashes = version_entities_to_delete
        .iter()
        .map(|version_entity| {
            SubgraphDeploymentId::new(
                version_entity
                    .get("deployment")
                    .unwrap()
                    .to_owned()
                    .as_string()
                    .unwrap(),
            )
            .unwrap()
        })
        .collect::<HashSet<_>>();
    // Find all subgraph version entities that point to these subgraph deployments
    let (version_summaries, read_summaries_ops) =
        store.read_subgraph_version_summaries(referenced_subgraph_hashes.into_iter().collect())?;
    ops.extend(read_summaries_ops);
    // Simulate the planned removal of SubgraphVersion entities
    let version_summaries_after_delete = version_summaries
        .clone()
        .into_iter()
        .filter(|version_summary| !version_entity_ids_to_delete.contains(&version_summary.id))
        .collect::<Vec<_>>();
    // Create/remove assignments based on the subgraph version changes.
    // We are only deleting versions here, so no assignments will be created,
    // and we can safely pass None for the node ID.
    ops.extend(store.reconcile_assignments(
        logger,
        version_summaries,
        version_summaries_after_delete,
        None,
    ));
    // Actually remove the subgraph version entities.
    // Note: we do this last because earlier AbortUnless ops depend on these entities still
    // existing.
    ops.extend(
        version_entities_to_delete
            .iter()
            .map(|version_entity| EntityOperation::Remove {
                key: SubgraphVersionEntity::key(version_entity.id().unwrap()),
            }),
    );
    Ok(ops)
}
fn remove_subgraph_versions ( logger : & Logger , store : Arc < impl Store > , version_entities_to_delete : Vec < Entity > , ) -> Result < Vec < EntityOperation > , SubgraphRegistrarError > { let mut ops = vec ! [ ] ; let version_entity_ids_to_delete = version_entities_to_delete . iter ( ) . map ( | version_entity | version_entity . id ( ) . unwrap ( ) ) . collect :: < HashSet < _ > > ( ) ; // Get hashes that are referenced by versions that will be deleted. // These are candidates for clean up. let referenced_subgraph_hashes = version_entities_to_delete . iter ( ) . map ( | version_entity | { SubgraphDeploymentId :: new ( version_entity . get ( " " ) . unwrap ( ) . to_owned ( ) . as_string ( ) . unwrap ( ) , ) . unwrap ( ) } ) . collect :: < HashSet < _ > > ( ) ; // Find all subgraph version entities that point to these subgraph deployments let ( version_summaries , read_summaries_ops ) = store . read_subgraph_version_summaries ( referenced_subgraph_hashes . into_iter ( ) . collect ( ) ) ? ; ops . extend ( read_summaries_ops ) ; // Simulate the planned removal of SubgraphVersion entities let version_summaries_after_delete = version_summaries . clone ( ) . into_iter ( ) . filter ( | version_summary | ! version_entity_ids_to_delete . contains ( & version_summary . id ) ) . collect :: < Vec < _ > > ( ) ; // Create/remove assignments based on the subgraph version changes. // We are only deleting versions here, so no assignments will be created, // and we can safely pass None for the node ID. ops . extend ( store . reconcile_assignments ( logger , version_summaries , version_summaries_after_delete , None , ) ) ; // Actually remove the subgraph version entities. // Note: we do this last because earlier AbortUnless ops depend on these entities still // existing. ops . extend ( version_entities_to_delete . iter ( ) . map ( | version_entity | EntityOperation :: Remove { key : SubgraphVersionEntity :: key ( version_entity . id ( ) . unwrap ( ) ) , } ) , ) ; Ok ( ops ) }
Remove a set of subgraph versions atomically.
Remove a set of subgraph versions atomically .
logger
&Logger
store
Arc<impl Store>
version_entities_to_delete
Vec<Entity>
logger
&Logger
store
Arc<impl Store>
version_entities_to_delete
Vec<Entity>