use super::*;
use std::collections::HashSet;
pub(super) async fn compute_file_link_updates(
store: &Store,
gotcha_key: &str,
old_files: &[String],
new_files: &[String],
) -> Vec<(String, Record)> {
let old_set: HashSet<&str> = old_files.iter().map(String::as_str).collect();
let new_set: HashSet<&str> = new_files.iter().map(String::as_str).collect();
let mut updates = Vec::new();
for file_path in new_set.difference(&old_set) {
let file_key = format!("file:{file_path}");
if let Ok(existing) = store.get(&file_key).await {
if let Some(record) = crate::store::gotcha_ops::stage_file_link_update(
existing, file_path, gotcha_key, true,
) {
updates.push((file_key, record));
}
}
}
for file_path in old_set.difference(&new_set) {
let file_key = format!("file:{file_path}");
if let Ok(Some(existing)) = store.get(&file_key).await {
if let Some(record) = crate::store::gotcha_ops::stage_file_link_update(
Some(existing),
file_path,
gotcha_key,
false,
) {
updates.push((file_key, record));
}
}
}
updates
}
pub(super) async fn apply_confirmation_propagation(
store: &Store,
affected_files: &[String],
updates: &mut Vec<(String, Record)>,
) {
let now = now_secs();
for file_path in affected_files {
let file_key = format!("file:{file_path}");
let staged = match updates.iter_mut().find(|(key, _)| key == &file_key) {
Some((_, record)) => record,
None => match store.get(&file_key).await {
Ok(Some(record)) => {
updates.push((file_key, record));
&mut updates.last_mut().expect("just pushed").1
}
_ => continue,
},
};
staged.confidence.confirmation_count += 1;
staged.updated_at = now;
staged.version.logical_clock += 1;
staged.version.wall_clock = now;
}
}