Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(node): prefer stored wire owner_did over lossy slug-local resolut…
…ion; mirror projection in GraphQL
  • Loading branch information
Gravirei committed Jul 15, 2026
commit db87e673c76f638fd3d4860a67e14e855e08fe4b
15 changes: 10 additions & 5 deletions crates/gitlawb-node/src/api/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ pub async fn list_ref_updates(
let caller = auth.as_ref().map(|e| e.0 .0.as_str());
let updates = collect_visible_ref_updates(&state.db, None, limit, caller).await?;

// Resolve the local owner_did for each row so locally-hosted repos
// display their canonical owner rather than a peer-supplied wire value.
// Prefer the stored wire owner_did (full DID, may differ from local
// record's trailing-segment match). Fall back to the local record's
// owner_did only for backward-compat rows (stored as None) that name a
// repo this node hosts, so legacy rows still display an owner.
let deduped = state.db.list_all_repos_deduped().await?;
let resolve_local = |slug: &str| -> Option<&str> {
for record in &deduped {
Expand All @@ -153,9 +155,12 @@ pub async fn list_ref_updates(
let events: Vec<serde_json::Value> = updates
.iter()
.map(|u| {
let owner_did = match resolve_local(&u.repo) {
Some(local) => serde_json::json!(local),
None => serde_json::json!(u.owner_did),
let owner_did = match &u.owner_did {
Some(wire) => serde_json::json!(wire),
None => match resolve_local(&u.repo) {
Some(local) => serde_json::json!(local),
None => serde_json::Value::Null,
},
};
serde_json::json!({
"id": u.id,
Expand Down
44 changes: 32 additions & 12 deletions crates/gitlawb-node/src/graphql/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,36 @@ impl QueryRoot {
.await
.map_err(|e| async_graphql::Error::new(e.to_string()))?;

// Match the REST feed's owner_did projection: prefer the stored wire
// value (full DID), fall back to the local record's owner for
// backward-compat rows (stored as None) that name a local repo.
let deduped = db
.list_all_repos_deduped()
.await
.map_err(|e| async_graphql::Error::new(e.to_string()))?;
let resolve_local = |slug: &str| -> Option<String> {
for record in &deduped {
if crate::visibility::ref_update_row_names_repo(record, slug) {
return Some(record.owner_did.clone());
}
}
None
};

Ok(updates
.into_iter()
.map(|u| RefUpdateType {
repo: u.repo,
ref_name: u.ref_name,
old_sha: u.old_sha,
new_sha: u.new_sha,
pusher_did: u.pusher_did,
node_did: u.node_did,
timestamp: u.timestamp,
owner_did: u.owner_did,
.map(|u| {
let owner_did = u.owner_did.or_else(|| resolve_local(&u.repo));
RefUpdateType {
repo: u.repo,
ref_name: u.ref_name,
old_sha: u.old_sha,
new_sha: u.new_sha,
pusher_did: u.pusher_did,
node_did: u.node_did,
timestamp: u.timestamp,
owner_did,
}
})
.collect())
}
Expand Down Expand Up @@ -264,9 +283,10 @@ mod tests {
row.get("repo").unwrap(),
&async_graphql::Value::from("z6MkOwner/openrepo")
);
assert!(
row.contains_key("ownerDid"),
"ownerDid must be present in the refUpdates response"
assert_eq!(
row.get("ownerDid").unwrap(),
&async_graphql::Value::from(OWNER),
"ownerDid must fall back to the local record's owner for legacy rows"
);
}

Expand Down