Skip to content
This repository was archived by the owner on Apr 4, 2026. It is now read-only.

Commit d4fe4f0

Browse files
fix: root parent hub
If parent is only a URL (no cast parent), this cast is the root with a URL parent.
1 parent c59e4b3 commit d4fe4f0

4 files changed

Lines changed: 24 additions & 9 deletions

File tree

src/backfill/root_parent_backfill.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ impl RootParentBackfill {
112112
cast.parent_fid,
113113
cast.parent_hash.as_deref(),
114114
cast.parent_url.as_deref(),
115+
Some(cast.fid),
116+
Some(&cast.hash),
115117
)
116118
.await
117119
{

src/core/root_parent_hub.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,19 @@ pub async fn find_root_parent_hub<H: HubClient>(
2424
parent_fid: Option<i64>,
2525
parent_hash: Option<&[u8]>,
2626
parent_url: Option<&str>,
27+
cast_fid: Option<i64>,
28+
cast_hash: Option<&[u8]>,
2729
) -> Result<Option<RootParentInfo>, Box<dyn std::error::Error + Send + Sync>> {
2830
// If there's no parent, this cast is a root
2931
if parent_fid.is_none() && parent_hash.is_none() && parent_url.is_none() {
3032
return Ok(None);
3133
}
3234

33-
// If parent is only a URL (no cast parent), return just the URL
35+
// If parent is only a URL (no cast parent), this cast is the root with a URL parent
3436
if parent_url.is_some() && parent_fid.is_none() && parent_hash.is_none() {
3537
return Ok(Some(RootParentInfo {
36-
root_parent_fid: None,
37-
root_parent_hash: None,
38+
root_parent_fid: cast_fid,
39+
root_parent_hash: cast_hash.map(|h| h.to_vec()),
3840
root_parent_url: parent_url.map(|s| s.to_string()),
3941
}));
4042
}
@@ -199,7 +201,7 @@ mod tests {
199201
assert_eq!(info.root_parent_hash, None);
200202
assert_eq!(info.root_parent_url, Some("https://example.com".to_string()));
201203
}
202-
204+
203205
#[test]
204206
fn test_combined_root_parent() {
205207
let info = RootParentInfo {
@@ -212,7 +214,7 @@ mod tests {
212214
assert_eq!(info.root_parent_hash, Some(vec![0xaa, 0xbb]));
213215
assert_eq!(info.root_parent_url, Some("https://example.com".to_string()));
214216
}
215-
217+
216218
#[test]
217219
fn test_root_parent_scenarios() {
218220
// Scenario 1: Root cast has no parent at all
@@ -222,7 +224,7 @@ mod tests {
222224
root_parent_url: None,
223225
};
224226
assert!(info1.root_parent_url.is_none());
225-
227+
226228
// Scenario 2: Root cast has a URL parent
227229
let info2 = RootParentInfo {
228230
root_parent_fid: Some(200),

src/processor/database.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ impl DatabaseProcessor {
7979
parent_fid,
8080
parent_hash.map(|h| h.as_slice()),
8181
parent_url,
82+
Some(data.fid as i64),
83+
Some(&msg.hash),
8284
)
8385
.await
8486
{

src/processor/root_parent_processor.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl RootParentProcessor {
2626
) -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
2727
if let Some(data) = &msg.data {
2828
if let Some(CastAddBody(cast_body)) = &data.body {
29-
let _fid = data.fid as i64;
29+
let fid = data.fid as i64;
3030
let hash = &msg.hash;
3131

3232
// Extract parent information
@@ -40,8 +40,15 @@ impl RootParentProcessor {
4040

4141
// Find root parent if this cast has a parent
4242
let root_info = if parent_fid.is_some() || parent_url.is_some() {
43-
find_root_parent_hub(&self.hub_client, parent_fid, parent_hash, parent_url)
44-
.await?
43+
find_root_parent_hub(
44+
&self.hub_client,
45+
parent_fid,
46+
parent_hash,
47+
parent_url,
48+
Some(fid),
49+
Some(hash),
50+
)
51+
.await?
4552
} else {
4653
None
4754
};
@@ -117,6 +124,8 @@ impl RootParentProcessor {
117124
cast.parent_fid,
118125
cast.parent_hash.as_deref(),
119126
cast.parent_url.as_deref(),
127+
cast.fid,
128+
Some(&hash),
120129
)
121130
.await
122131
{

0 commit comments

Comments
 (0)