0
2
server: Backfill records an account's handle
Only what this pull adds. It is built on grain runs on a Rust server modelled on knotless, without hatk.
crates/grain-serve/src/backfill.rs+12−4
| @@ -20,6 +20,8 @@ | ||
//! at, and what the index has from a later one (a write or deletion the | ||
//! stream applied since) stands. What the index has of the account that | ||
//! the repo no longer does is deleted, unless it is newer than the repo. | ||
//! Its handle is the one its document claims, if that names it back: the | ||
//! stream names a handle only when it changes. | ||
//! | ||
//! The queue is the index's `repo` table: a few repos are read at once, at | ||
//! most a few from any one host, and one that fails is tried again later, | ||
| @@ -366,10 +368,16 @@ impl Backfill { | ||
} | ||
}; | ||
let index = self.index.clone(); | ||
let did = did.to_string(); | ||
let apply = move || apply(&index, &did, read, mirrored); | ||
let done = tokio::task::spawn_blocking(apply).await.map_err(retry)?; | ||
done.map(Some) | ||
let owned = did.to_string(); | ||
let apply = move || apply(&index, &owned, read, mirrored); | ||
let done = tokio::task::spawn_blocking(apply).await.map_err(retry)??; | ||
// The stream names an account's handle only when it changes, so one | ||
// tracked from its first write would otherwise have none: it is the | ||
// handle its document claims, if that names it back. | ||
if let Some(handle) = identity::handle(&self.ctx, did).await { | ||
self.index.set_handle(did, &handle).map_err(retry)?; | ||
} | ||
Ok(Some(done)) | ||
} | ||
| ||
/// `did`'s repo from `base`'s `getRepo`, read as it streams and checked | ||
crates/grain-serve/tests/backfill.rs+3−0
| @@ -296,6 +296,9 @@ async fn repos_read_from_the_mirror_or_else_the_pds() { | ||
(queued.state.as_str(), queued.rev), | ||
("active", Some(done.rev)) | ||
); | ||
// Its handle is the one its document claims, which names it back. | ||
let (handle, _) = index.repo(&a.did).unwrap().unwrap(); | ||
assert_eq!(handle.as_deref(), Some(a.handle.as_str())); | ||
let (_, accept) = stand.asked.lock().unwrap()[0].clone(); | ||
assert!( | ||
accept.starts_with("application/x.microcosm.star-lite"), | ||