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

Method operation_log

atomic-repository/src/repository/operation.rs:1186–1309  ·  view source on GitHub ↗

Return operations reachable from a scope's heads in deterministic causal order. Children always precede parents unless `reverse` is true. Timestamps are used only to order causally independent ready nodes, with the operation ID as a deterministic tie-breaker.

(
        &self,
        scope: OperationScope,
        limit: Option<usize>,
        reverse: bool,
    )

Source from the content-addressed store, hash-verified

1184 /// only to order causally independent ready nodes, with the operation ID as a
1185 /// deterministic tie-breaker.
1186 pub fn operation_log(
1187 &self,
1188 scope: OperationScope,
1189 limit: Option<usize>,
1190 reverse: bool,
1191 ) -> Result<OperationLog, RepositoryError> {
1192 let txn = self.pristine.read_txn().map_err(pristine_error)?;
1193 let heads = txn.get_operation_heads(scope).map_err(pristine_error)?;
1194 let head_state = match heads.as_slice() {
1195 [] => OperationHeadState::Empty,
1196 [head] => OperationHeadState::Single(*head),
1197 many => OperationHeadState::Diverged(many.to_vec()),
1198 };
1199 let head_ids: BTreeSet<OperationId> = heads.as_slice().iter().copied().collect();
1200 let operations: BTreeMap<OperationId, Operation> = txn
1201 .list_operations()
1202 .map_err(pristine_error)?
1203 .into_iter()
1204 .map(|operation| (operation.id(), operation))
1205 .collect();
1206
1207 let mut reachable = BTreeSet::new();
1208 let mut pending = heads.as_slice().to_vec();
1209 while let Some(operation_id) = pending.pop() {
1210 if !reachable.insert(operation_id) {
1211 continue;
1212 }
1213 let operation = operations.get(&operation_id).ok_or_else(|| {
1214 RepositoryError::OperationNotFound {
1215 selector: operation_id.to_string(),
1216 }
1217 })?;
1218 pending.extend(operation.payload().parents.iter().copied());
1219 }
1220
1221 let mut child_counts: BTreeMap<OperationId, usize> = reachable
1222 .iter()
1223 .copied()
1224 .map(|operation_id| (operation_id, 0))
1225 .collect();
1226 for operation_id in &reachable {
1227 let operation =
1228 operations
1229 .get(operation_id)
1230 .ok_or_else(|| RepositoryError::OperationNotFound {
1231 selector: operation_id.to_string(),
1232 })?;
1233 for parent in &operation.payload().parents {
1234 if let Some(count) = child_counts.get_mut(parent) {
1235 *count += 1;
1236 }
1237 }
1238 }
1239
1240 let mut ready: BTreeSet<(i64, OperationId)> = child_counts
1241 .iter()
1242 .filter(|(_, count)| **count == 0)
1243 .map(|(operation_id, _)| {

Calls 15

read_txnMethod · 0.80
extendMethod · 0.80
get_mutMethod · 0.80
truncateMethod · 0.80
getMethod · 0.65
removeMethod · 0.65
get_operation_headsMethod · 0.45
as_sliceMethod · 0.45
collectMethod · 0.45
iterMethod · 0.45
into_iterMethod · 0.45