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

Function preview_unrecord

atomic-repository/src/unrecord.rs:615–658  ·  view source on GitHub ↗

Preview what would be unrecorded without actually doing it. # Arguments `txn` - Read transaction `view` - View to preview `hashes` - Hashes of changes to unrecord `options` - Unrecord options # Returns An `UnrecordOutcome` describing what would happen.

(
    txn: &T,
    view: &ViewState,
    hashes: &[Hash],
    options: &UnrecordOptions,
)

Source from the content-addressed store, hash-verified

613///
614/// An `UnrecordOutcome` describing what would happen.
615pub fn preview_unrecord<T: ViewTxnT>(
616 txn: &T,
617 view: &ViewState,
618 hashes: &[Hash],
619 options: &UnrecordOptions,
620) -> UnrecordResult<UnrecordOutcome> {
621 let mut all_unrecords = Vec::new();
622
623 for hash in hashes {
624 if options.cascade {
625 let set = find_unrecord_set(txn, view, hash, options.max_cascade)?;
626 for h in set {
627 if !all_unrecords.contains(&h) {
628 all_unrecords.push(h);
629 }
630 }
631 } else {
632 // Check if can unrecord without cascade
633 let info = check_can_unrecord(txn, view, hash, options)?;
634 if !info.can_unrecord {
635 return Err(UnrecordError::HasDependents {
636 hash: hash.to_base32(),
637 dependents: info.dependents.iter().map(|h| h.to_base32()).collect(),
638 });
639 }
640 if !all_unrecords.contains(hash) {
641 all_unrecords.push(*hash);
642 }
643 }
644 }
645
646 // Compute new state
647 let removed_set: HashSet<Hash> = all_unrecords.iter().copied().collect();
648 let new_state = compute_state_after_unrecord(txn, view, &removed_set)?;
649 let new_count = view.change_count - all_unrecords.len() as u64;
650
651 let mut stats = UnrecordStats::new();
652 stats.direct_unrecords = hashes.len();
653 stats.cascaded_unrecords = all_unrecords.len() - hashes.len();
654
655 Ok(UnrecordOutcome::new(all_unrecords, new_state, new_count)
656 .as_dry_run()
657 .with_stats(stats))
658}
659
660/// Get the sequence number of the last change in a view.
661///

Callers 1

unrecordMethod · 0.85

Calls 10

find_unrecord_setFunction · 0.85
check_can_unrecordFunction · 0.85
with_statsMethod · 0.80
as_dry_runMethod · 0.80
containsMethod · 0.45
pushMethod · 0.45
to_base32Method · 0.45
iterMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected