diff --git a/src/api/xrpc/resolve_mini_doc.rs b/src/api/xrpc/resolve_mini_doc.rs index c617cb6..76fcbd1 100644 --- a/src/api/xrpc/resolve_mini_doc.rs +++ b/src/api/xrpc/resolve_mini_doc.rs @@ -86,14 +86,19 @@ pub(super) async fn resolve_mini_doc( .await .map_err(|e| bad_request(nsid, format!("can't resolve identifier: {e}")))?; - let doc = hydrant.repos.get(&did).mini_doc().await.map_err(|e| match e { - MiniDocError::NotSynced => bad_request(nsid, "repo not synced"), - MiniDocError::RepoNotFound => bad_request(nsid, "repo not found"), - MiniDocError::CouldNotResolveIdentity => { - upstream_error(nsid, "identity could not be resolved") - } - MiniDocError::Other(e) => internal_error(nsid, e), - })?; + let doc = hydrant + .repos + .get(&did) + .mini_doc() + .await + .map_err(|e| match e { + MiniDocError::NotSynced => bad_request(nsid, "repo not synced"), + MiniDocError::RepoNotFound => bad_request(nsid, "repo not found"), + MiniDocError::CouldNotResolveIdentity => { + upstream_error(nsid, "identity could not be resolved") + } + MiniDocError::Other(e) => internal_error(nsid, e), + })?; Ok(ResolveMiniDocOutput { did: doc.did, diff --git a/src/control/repos/mod.rs b/src/control/repos/mod.rs index e279efa..51f98b6 100644 --- a/src/control/repos/mod.rs +++ b/src/control/repos/mod.rs @@ -170,7 +170,9 @@ pub(crate) fn repo_state_to_info(did: Did<'static>, s: RepoState<'_>, tracked: b pds: s.pds.and_then(|p| p.parse().ok()), signing_key: s.signing_key.map(|k| k.into_static()), last_updated_at: DateTime::from_timestamp_secs(s.last_updated_at), - last_message_at: s.last_message_time.and_then(DateTime::from_timestamp_secs), + last_message_at: s + .last_message_time + .and_then(DateTime::from_timestamp_millis), } } @@ -180,6 +182,32 @@ pub struct Record { pub value: Data<'static>, } +#[cfg(test)] +mod tests { + use super::*; + use miette::IntoDiagnostic; + + #[test] + fn repo_info_renders_message_time_from_millis() -> miette::Result<()> { + let mut state = RepoState::backfilling(); + state.last_updated_at = 1_783_785_600; + state.last_message_time = Some(1_783_785_600_123); + + let info = repo_state_to_info(Did::new("did:plc:testrepo").into_diagnostic()?, state, true); + + assert_eq!( + info.last_updated_at.map(|t| t.timestamp()), + Some(1_783_785_600) + ); + assert_eq!( + info.last_message_at + .map(|t| (t.timestamp(), t.timestamp_subsec_millis())), + Some((1_783_785_600, 123)) + ); + Ok(()) + } +} + pub struct ListedRecord { pub rkey: Rkey<'static>, pub cid: Cid<'static>, diff --git a/src/ingest/relay.rs b/src/ingest/relay.rs index c3bac97..67a9296 100644 --- a/src/ingest/relay.rs +++ b/src/ingest/relay.rs @@ -1278,7 +1278,7 @@ impl WorkerContext<'_> { }; #[cfg(all(feature = "relay", not(feature = "indexer")))] - let mut repo_state = RepoState::backfilling(); + let mut repo_state = RepoState::synced(); repo_state.update_from_doc(doc); RelayWorker::update_pds_account_count( diff --git a/src/types.rs b/src/types.rs index 1105b47..af301c0 100644 --- a/src/types.rs +++ b/src/types.rs @@ -298,6 +298,13 @@ impl<'i> RepoState<'i> { } } + pub fn synced() -> Self { + Self { + status: RepoStatus::Synced, + ..Self::backfilling() + } + } + // advances the high-water mark to event_ms if it's newer than what we've seen pub fn advance_message_time(&mut self, event_ms: i64) { self.last_message_time = Some(event_ms.max(self.last_message_time.unwrap_or(0))); @@ -719,6 +726,14 @@ mod tests { assert!(state.should_process_account_time(2_501)); } + #[test] + fn synced_state_is_active_without_backfilling_status() { + let state = RepoState::synced(); + assert!(state.active); + assert_eq!(state.status, RepoStatus::Synced); + assert!(state.root.is_none()); + } + #[test] fn into_static_preserves_per_event_clocks() -> miette::Result<()> { let mut state = RepoState::backfilling();