//! the one-off `listRepos` walk an indexer owes a PDS it starts following. //! //! a new PDS is tailed from the relay's seq, so repos that already lived on it //! never reach us as events and nothing else lists them. only hosts that are new //! to the network get the walk: a seed relay's hosts count as bootstrap until its //! `listHosts` has been read to the end once, otherwise a fresh node would walk //! every PDS out there. a relay has nothing to backfill, so there it's a no-op. #[cfg(feature = "indexer")] mod enabled { use miette::{IntoDiagnostic, Result}; use smol_str::SmolStr; use url::Url; use crate::db::{Db, keys}; use crate::state::AppState; /// stage the walk in the batch that admits the host, so a restart can't lose it. pub(crate) fn queue(batch: &mut fjall::OwnedWriteBatch, db: &Db, host: &str) -> Result<()> { batch.insert( &db.cursors, keys::new_pds_crawl_key(host), encode_cursor(None)?, ); Ok(()) } /// call once the batch from [`queue`] has committed. pub(crate) fn wake(state: &AppState) { state.new_pds_crawl_notify.notify_one(); } pub(crate) fn seed_listed(db: &Db, seed: &Url) -> Result { db.cursors .contains_key(keys::seed_listed_key(seed.as_str())) .into_diagnostic() } pub(crate) fn mark_seed_listed(db: &Db, seed: &Url) -> Result<()> { db.cursors .insert(keys::seed_listed_key(seed.as_str()), b"") .into_diagnostic() } pub(crate) fn encode_cursor(cursor: Option<&SmolStr>) -> Result> { rmp_serde::to_vec(&cursor).into_diagnostic() } pub(crate) fn decode_cursor(bytes: &[u8]) -> Result> { rmp_serde::from_slice(bytes).into_diagnostic() } } #[cfg(feature = "indexer")] pub(crate) use enabled::*; #[cfg(not(feature = "indexer"))] mod noop { use miette::Result; use url::Url; use crate::db::Db; use crate::state::AppState; pub(crate) fn queue(_batch: &mut fjall::OwnedWriteBatch, _db: &Db, _host: &str) -> Result<()> { Ok(()) } pub(crate) fn wake(_state: &AppState) {} pub(crate) fn seed_listed(_db: &Db, _seed: &Url) -> Result { Ok(false) } pub(crate) fn mark_seed_listed(_db: &Db, _seed: &Url) -> Result<()> { Ok(()) } } #[cfg(not(feature = "indexer"))] pub(crate) use noop::*;