Load and process relay lists from the database at startup

This commit is contained in:
Mike Dilger 2023-02-05 10:51:31 +13:00
parent ac242978f5
commit cfb5bc820c
2 changed files with 36 additions and 0 deletions

View File

@ -75,6 +75,29 @@ impl DbEvent {
Ok(output?.drain(..).next())
}
pub async fn fetch_relay_lists() -> Result<Vec<Event>, Error> {
// FIXME, only get the last per pubkey
let sql = "SELECT raw FROM event WHERE event.kind=10002";
let output: Result<Vec<Event>, Error> = spawn_blocking(move || {
let maybe_db = GLOBALS.db.blocking_lock();
let db = maybe_db.as_ref().unwrap();
let mut stmt = db.prepare(sql)?;
let mut rows = stmt.raw_query();
let mut events: Vec<Event> = Vec::new();
while let Some(row) = rows.next()? {
let raw: String = row.get(0)?;
let event: Event = serde_json::from_str(&raw)?;
events.push(event);
}
Ok(events)
})
.await?;
output
}
pub async fn fetch_reply_related(since: i64) -> Result<Vec<DbEvent>, Error> {
let public_key: PublicKeyHex = match GLOBALS.signer.public_key() {
None => return Ok(vec![]),

View File

@ -196,6 +196,19 @@ impl Overlord {
tracing::info!("Loaded {} feed related events from the database", count);
}
// Load relay lists from the database and process
{
let events: Vec<Event> = DbEvent::fetch_relay_lists().await?;
// Process these events
let mut count = 0;
for event in events.iter() {
count += 1;
crate::process::process_new_event(event, false, None, None).await?;
}
tracing::info!("Loaded {} relay list events from the database", count);
}
// Pick Relays and start Minions
if !GLOBALS.settings.read().await.offline {
// Create a new RelayPicker