From f330dcd366b061b7966dbeb73594b26c1a2d3395 Mon Sep 17 00:00:00 2001 From: Lewis Date: Sat, 11 Jul 2026 16:14:56 +0300 Subject: [PATCH] types: did, nsid, & rkey in AtUri::from_parts Lewis: May this revision serve well! --- crates/tranquil-api/src/repo/import.rs | 16 +++++----------- crates/tranquil-pds/src/repo_ops.rs | 2 +- crates/tranquil-pds/src/scheduled.rs | 16 +++------------- crates/tranquil-pds/tests/repo_batch.rs | 6 +++++- .../tranquil-store/src/metastore/backlink_ops.rs | 8 ++++++++ .../tranquil-store/src/metastore/commit_ops.rs | 12 ++++++++---- crates/tranquil-types/src/lib.rs | 2 +- 7 files changed, 31 insertions(+), 31 deletions(-) diff --git a/crates/tranquil-api/src/repo/import.rs b/crates/tranquil-api/src/repo/import.rs index e63ede1..e49d0c3 100644 --- a/crates/tranquil-api/src/repo/import.rs +++ b/crates/tranquil-api/src/repo/import.rs @@ -167,17 +167,11 @@ pub async fn import_repo( .records .iter() .flat_map(|record| { - let record_uri = - AtUri::from_parts(did.as_str(), &record.collection, &record.rkey); - record.blob_refs.iter().filter_map(move |blob_ref| { - match CidLink::new(&blob_ref.cid) { - Ok(cid_link) => Some((record_uri.clone(), cid_link)), - Err(_) => { - tracing::warn!(cid = %blob_ref.cid, "skipping unparseable blob CID reference during import"); - None - } - } - }) + let record_uri = AtUri::from_parts(did, &record.collection, &record.rkey); + record + .blob_refs + .iter() + .map(move |blob_ref| (record_uri.clone(), blob_ref.cid.clone())) }) .collect(); diff --git a/crates/tranquil-pds/src/repo_ops.rs b/crates/tranquil-pds/src/repo_ops.rs index e183e82..3d8dbad 100644 --- a/crates/tranquil-pds/src/repo_ops.rs +++ b/crates/tranquil-pds/src/repo_ops.rs @@ -978,7 +978,7 @@ pub async fn create_record_internal( cid: RecordCid::from(record_cid), }; let blob_cids = extract_blob_cids(record); - let record_uri = AtUri::from_parts(did.as_str(), collection.as_str(), rkey.as_str()); + let record_uri = AtUri::from_parts(did, collection, rkey); let backlinks = extract_backlinks(&record_uri, record); let result = finalize_repo_write( diff --git a/crates/tranquil-pds/src/scheduled.rs b/crates/tranquil-pds/src/scheduled.rs index 93f8da7..e36b063 100644 --- a/crates/tranquil-pds/src/scheduled.rs +++ b/crates/tranquil-pds/src/scheduled.rs @@ -242,19 +242,9 @@ async fn process_record_blobs( Some( blob_refs .into_iter() - .filter_map(|blob_ref| { - let record_uri = AtUri::from_parts( - did.as_str(), - record.collection.as_str(), - record.rkey.as_str(), - ); - match CidLink::new(&blob_ref.cid) { - Ok(cid_link) => Some((record_uri, cid_link)), - Err(_) => { - tracing::warn!(cid = %blob_ref.cid, "skipping unparseable blob CID in record blob backfill"); - None - } - } + .map(|blob_ref| { + let record_uri = AtUri::from_parts(&did, &record.collection, &record.rkey); + (record_uri, blob_ref.cid) }) .collect::>(), ) diff --git a/crates/tranquil-pds/tests/repo_batch.rs b/crates/tranquil-pds/tests/repo_batch.rs index 32dc89c..9a4e97d 100644 --- a/crates/tranquil-pds/tests/repo_batch.rs +++ b/crates/tranquil-pds/tests/repo_batch.rs @@ -511,7 +511,11 @@ async fn repo_id_for_did(did: &str) -> uuid::Uuid { async fn follow_uris_pointing_to(repo_id: uuid::Uuid, target_did: &str) -> Vec { let repos = get_test_repos().await; let probe = Backlink { - uri: AtUri::from_parts("did:plc:probe", "app.bsky.graph.follow", "probe"), + uri: AtUri::from_parts( + &Did::from("did:plc:periwinkle".to_string()), + &Nsid::from("app.bsky.graph.follow".to_string()), + &Rkey::from("probe".to_string()), + ), path: BacklinkPath::Subject, link_to: target_did.to_string(), }; diff --git a/crates/tranquil-store/src/metastore/backlink_ops.rs b/crates/tranquil-store/src/metastore/backlink_ops.rs index 97319a3..8da1c07 100644 --- a/crates/tranquil-store/src/metastore/backlink_ops.rs +++ b/crates/tranquil-store/src/metastore/backlink_ops.rs @@ -208,6 +208,14 @@ mod tests { use tranquil_db_traits::{Backlink, BacklinkPath}; use tranquil_types::{Did, Handle, Nsid}; + fn test_uri(did: &str, collection: &str, rkey: &str) -> AtUri { + AtUri::from_parts( + &did.parse().unwrap(), + &collection.parse().unwrap(), + &rkey.parse().unwrap(), + ) + } + struct TestHarness { _dir: tempfile::TempDir, metastore: Metastore, diff --git a/crates/tranquil-store/src/metastore/commit_ops.rs b/crates/tranquil-store/src/metastore/commit_ops.rs index 49b0502..a5bf2f6 100644 --- a/crates/tranquil-store/src/metastore/commit_ops.rs +++ b/crates/tranquil-store/src/metastore/commit_ops.rs @@ -871,7 +871,11 @@ mod tests { let needing = ops.get_users_needing_record_blobs_backfill(100).unwrap(); assert_eq!(needing.len(), 2); - let uri = AtUri::from_parts(did_a.as_str(), "app.bsky.feed.post", "3k2abc"); + let uri = AtUri::from_parts( + &did_a, + &"app.bsky.feed.post".parse().unwrap(), + &"3k2abc".parse().unwrap(), + ); let blob_cid = test_cid_link(62); ops.insert_record_blobs(user_id_a, &[uri], &[blob_cid]) .unwrap(); @@ -967,7 +971,7 @@ mod tests { let collection = Nsid::from("app.bsky.feed.like".to_string()); let rkey = Rkey::from("3k2like1".to_string()); let record_cid = test_cid_link(91); - let record_uri = AtUri::from_parts(did.as_str(), collection.as_str(), rkey.as_str()); + let record_uri = AtUri::from_parts(&did, &collection, &rkey); let mid_root = test_cid_link(92); let create_input = ApplyCommitInput { @@ -1343,8 +1347,8 @@ mod tests { let target = "at://did:plc:someone/app.bsky.feed.post/p1"; let mid_root = test_cid_link(96); - let uri_like = AtUri::from_parts(did.as_str(), col_like.as_str(), rkey.as_str()); - let uri_repost = AtUri::from_parts(did.as_str(), col_repost.as_str(), rkey.as_str()); + let uri_like = AtUri::from_parts(&did, &col_like, &rkey); + let uri_repost = AtUri::from_parts(&did, &col_repost, &rkey); let input = ApplyCommitInput { user_id, diff --git a/crates/tranquil-types/src/lib.rs b/crates/tranquil-types/src/lib.rs index c27191b..a50b928 100644 --- a/crates/tranquil-types/src/lib.rs +++ b/crates/tranquil-types/src/lib.rs @@ -411,7 +411,7 @@ validated_string_newtype! { } impl AtUri { - pub fn from_parts(did: &str, collection: &str, rkey: &str) -> Self { + pub fn from_parts(did: &Did, collection: &Nsid, rkey: &Rkey) -> Self { Self(format!("at://{}/{}/{}", did, collection, rkey)) }