1
Fork 0
mirror of https://github.com/thegeneralist01/archivr synced 2026-12-04 18:56:44 +01:00

fix: stop thread export traversal at visited posts

This commit is contained in:
TheGeneralist 2026-10-13 14:52:40 +02:00
parent e8767d221e
commit cfc87e9859
Signed by: thegeneralist01
SSH key fingerprint: SHA256:pp9qddbCNmVNoSjevdvQvM5z0DHN7LTa8qBMbcMq/R4

View file

@ -453,7 +453,9 @@ fn dfs(
Some(s) => s,
None => return,
};
conversation_ids.insert(id.to_string());
if !conversation_ids.insert(id.to_string()) {
return;
}
let post = parse_post(status, asset_map, Some(conversation_ids));
out.push(post);
if let Some(children) = children_map.get(id) {
@ -718,3 +720,30 @@ fn decode_html_entities(s: &str) -> String {
.replace(""", "\"")
.replace("'", "'")
}
#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;
#[test]
fn thread_export_visits_each_post_once_when_replies_cycle() {
for statuses in [
vec![json!({"id_str": "1", "in_reply_to_status_id_str": "1"})],
vec![
json!({"id_str": "1", "in_reply_to_status_id_str": "2"}),
json!({"id_str": "2", "in_reply_to_status_id_str": "1"}),
],
] {
let status_map: HashMap<String, serde_json::Value> = statuses
.iter()
.map(|status| (tweet_id(status).unwrap(), status.clone()))
.collect();
let posts = build_thread(&statuses, &status_map, Some("1"), &HashMap::new());
let unique_ids: HashSet<&str> = posts.iter().map(|post| post._id.as_str()).collect();
assert_eq!(posts.len(), statuses.len());
assert_eq!(unique_ids.len(), statuses.len());
}
}
}