MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / del_change

Method del_change

atomic-core/src/pristine/txn/write/mod.rs:1123–1248  ·  view source on GitHub ↗
(
        &mut self,
        view: &mut ViewState,
        change_id: NodeId,
        _change_hash: &Hash,
    )

Source from the content-addressed store, hash-verified

1121 }
1122
1123 fn del_change(
1124 &mut self,
1125 view: &mut ViewState,
1126 change_id: NodeId,
1127 _change_hash: &Hash,
1128 ) -> PristineResult<Option<u64>> {
1129 // Find the sequence number for this change
1130 let seq = {
1131 let table = self.txn.open_table(REV_VIEW_CHANGES)?;
1132 let key = encode_view_seq(view.id, change_id.get());
1133 let result = table.get(&key)?;
1134 match result {
1135 Some(value) => {
1136 let v = value.value();
1137 drop(value);
1138 v
1139 }
1140 None => return Ok(None), // Change not in this view
1141 }
1142 };
1143
1144 // Remove from VIEW_CHANGES
1145 {
1146 let mut table = self.txn.open_table(VIEW_CHANGES)?;
1147 let key = encode_view_seq(view.id, seq);
1148 table.remove(&key)?;
1149 }
1150
1151 // Remove from REV_VIEW_CHANGES
1152 {
1153 let mut table = self.txn.open_table(REV_VIEW_CHANGES)?;
1154 let key = encode_view_seq(view.id, change_id.get());
1155 table.remove(&key)?;
1156 }
1157
1158 // Remove from MERKLE_CHAIN (the merkle state at this sequence)
1159 {
1160 let mut table = self.txn.open_table(MERKLE_CHAIN)?;
1161 let key = encode_view_seq(view.id, seq);
1162 table.remove(&key)?;
1163 }
1164
1165 // Shift all subsequent changes down by 1
1166 // We need to update sequences from seq+1 to change_count-1
1167 let original_count = view.change_count;
1168 for s in (seq + 1)..original_count {
1169 // Get the change_id at this sequence
1170 let cid = {
1171 let table = self.txn.open_table(VIEW_CHANGES)?;
1172 let key = encode_view_seq(view.id, s);
1173 let result = table.get(&key)?;
1174 match result {
1175 Some(v) => {
1176 let id = NodeId::new(v.value());
1177 drop(v);
1178 id
1179 }
1180 None => continue,

Callers 6

test_del_changeFunction · 0.80
split_viewMethod · 0.80
unrecordMethod · 0.80
retain_view_changesMethod · 0.80

Calls 8

encode_view_seqFunction · 0.85
encode_view_merkleFunction · 0.85
getMethod · 0.65
removeMethod · 0.65
insertMethod · 0.45
get_externalMethod · 0.45
nextMethod · 0.45
as_bytesMethod · 0.45

Tested by 3

test_del_changeFunction · 0.64