/// Remove all artifacts with heights less than the given HeightKey.
Remove all artifacts with heights less than the given HeightKey.
Remove all artifacts with heights less than the given HeightKey .
fn tx_purge_below<'a>(
        &self,
        tx: &mut RwTransaction<'a>,
        height_key: HeightKey,
    ) -> lmdb::Result<()> {
        // delete from all index tables
        for type_key in Artifact::type_keys() {
            // only delete if meta exists
            if let Some(meta) = self.get_meta(tx, type_key) {
                // skip to next db if min height is already higher
                if meta.min >= height_key {
                    continue;
                }
                let index_db = self.get_index_db(type_key);
                {
                    let mut cursor = tx.open_rw_cursor(index_db)?;
                    loop {
                        match cursor.iter().next().transpose()? {
                            None => break,
                            Some((key, _)) => {
                                if HeightKey::from(key) >= height_key {
                                    break;
                                }
                                cursor.del(WriteFlags::empty())?;
                            }
                        }
                    }
                }
                let meta = if meta.max <= height_key {
                    None
                } else {
                    let mut cursor = tx.open_rw_cursor(index_db)?;
                    cursor
                        .iter_start()
                        .next()
                        .transpose()?
                        .map(|(key, _)| Meta {
                            min: HeightKey::from(key),
                            max: meta.max,
                        })
                };
                match meta {
                    None => tx.del(self.meta, &type_key, None)?,
                    Some(meta) => self.update_meta(tx, type_key, &meta)?,
                }
            }
        }
        // delete from artifacts table
        let mut cursor = tx.open_rw_cursor(self.artifacts)?;
        let height = Height::from(height_key);
        loop {
            match cursor.iter().next().transpose()? {
                None => break,
                Some((key, _)) => {
                    let id_key = IdKey::from(key);
                    if id_key.height() >= height {
                        break;
                    }
                    cursor.del(WriteFlags::empty())?;
                }
            }
        }
        Ok(())
    }
fn tx_purge_below < ' a > ( & self , tx : & mut RwTransaction < ' a > , height_key : HeightKey , ) -> lmdb :: Result < ( ) > { // delete from all index tables for type_key in Artifact :: type_keys ( ) { // only delete if meta exists if let Some ( meta ) = self . get_meta ( tx , type_key ) { // skip to next db if min height is already higher if meta . min >= height_key { continue ; } let index_db = self . get_index_db ( type_key ) ; { let mut cursor = tx . open_rw_cursor ( index_db ) ? ; loop { match cursor . iter ( ) . next ( ) . transpose ( ) ? { None => break , Some ( ( key , _ ) ) => { if HeightKey :: from ( key ) >= height_key { break ; } cursor . del ( WriteFlags :: empty ( ) ) ? ; } } } } let meta = if meta . max <= height_key { None } else { let mut cursor = tx . open_rw_cursor ( index_db ) ? ; cursor . iter_start ( ) . next ( ) . transpose ( ) ? . map ( | ( key , _ ) | Meta { min : HeightKey :: from ( key ) , max : meta . max , } ) } ; match meta { None => tx . del ( self . meta , & type_key , None ) ? , Some ( meta ) => self . update_meta ( tx , type_key , & meta ) ? , } } } // delete from artifacts table let mut cursor = tx . open_rw_cursor ( self . artifacts ) ? ; let height = Height :: from ( height_key ) ; loop { match cursor . iter ( ) . next ( ) . transpose ( ) ? { None => break , Some ( ( key , _ ) ) => { let id_key = IdKey :: from ( key ) ; if id_key . height ( ) >= height { break ; } cursor . del ( WriteFlags :: empty ( ) ) ? ; } } } Ok ( ( ) ) }
Remove all artifacts with heights less than the given HeightKey.
Remove all artifacts with heights less than the given HeightKey .
&self
tx
&mut RwTransaction<'a>
height_key
HeightKey