types: did, nsid, & rkey in AtUri::from_parts

Lewis: May this revision serve well! <lu5a@proton.me>
This commit is contained in:
Lewis
2026-07-11 16:14:56 +03:00
parent 1411506d8c
commit f330dcd366
7 changed files with 31 additions and 31 deletions
+5 -11
View File
@@ -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();
+1 -1
View File
@@ -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(
+3 -13
View File
@@ -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::<Vec<_>>(),
)
+5 -1
View File
@@ -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<String> {
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(),
};
@@ -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,
@@ -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,
+1 -1
View File
@@ -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))
}