From 6486aff54a2df9e967959e0ffef11fb894f78381 Mon Sep 17 00:00:00 2001 From: Ryan Breen Date: Wed, 22 Nov 2023 21:12:21 -0500 Subject: [PATCH] fix: publis command should not use queue --- nomen/src/db/relay_index.rs | 14 +++++++++++++- nomen/src/subcommands/index/events/relay_index.rs | 8 ++++++-- nomen/src/subcommands/index/mod.rs | 2 +- nomen/src/subcommands/mod.rs | 2 +- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/nomen/src/db/relay_index.rs b/nomen/src/db/relay_index.rs index 53f3841..2f7b042 100644 --- a/nomen/src/db/relay_index.rs +++ b/nomen/src/db/relay_index.rs @@ -18,7 +18,7 @@ pub struct Name { pub records: String, } -pub async fn fetch_all( +pub async fn fetch_all_queued( conn: impl sqlx::Executor<'_, Database = Sqlite> + Copy, ) -> anyhow::Result> { let results = sqlx::query_as::<_, Name>( @@ -31,6 +31,18 @@ pub async fn fetch_all( Ok(results) } +pub async fn fetch_all( + conn: impl sqlx::Executor<'_, Database = Sqlite> + Copy, +) -> anyhow::Result> { + let results = sqlx::query_as::<_, Name>( + "SELECT vnr.name, vnr.pubkey, COALESCE(vnr.records, '{}') as records + FROM valid_names_records_vw vnr;", + ) + .fetch_all(conn) + .await?; + Ok(results) +} + pub async fn delete( conn: impl sqlx::Executor<'_, Database = Sqlite> + Copy, name: &str, diff --git a/nomen/src/subcommands/index/events/relay_index.rs b/nomen/src/subcommands/index/events/relay_index.rs index 95c0ea7..ba5c9ad 100644 --- a/nomen/src/subcommands/index/events/relay_index.rs +++ b/nomen/src/subcommands/index/events/relay_index.rs @@ -10,7 +10,7 @@ use crate::{ db::{self, relay_index::Name}, }; -pub async fn publish(config: &Config, pool: &SqlitePool) -> anyhow::Result<()> { +pub async fn publish(config: &Config, pool: &SqlitePool, use_queue: bool) -> anyhow::Result<()> { if !config.publish_index() { return Ok(()); } @@ -22,7 +22,11 @@ pub async fn publish(config: &Config, pool: &SqlitePool) -> anyhow::Result<()> { let (_, client) = config.nostr_random_client().await?; tracing::info!("Publishing relay index."); - let names = db::relay_index::fetch_all(pool).await?; + let names = if use_queue { + db::relay_index::fetch_all_queued(pool).await? + } else { + db::relay_index::fetch_all(pool).await? + }; send_events(pool, names, keys, &client).await?; tracing::info!("Publishing relay index complete."); diff --git a/nomen/src/subcommands/index/mod.rs b/nomen/src/subcommands/index/mod.rs index 85fd8ac..05ae272 100644 --- a/nomen/src/subcommands/index/mod.rs +++ b/nomen/src/subcommands/index/mod.rs @@ -7,7 +7,7 @@ pub async fn index(config: &Config) -> anyhow::Result<()> { let pool = config.sqlite().await?; blockchain::index(config, &pool).await?; events::records(config, &pool).await?; - events::relay_index::publish(config, &pool).await?; + events::relay_index::publish(config, &pool, true).await?; db::event_log::save(&pool, "index", "").await?; Ok(()) diff --git a/nomen/src/subcommands/mod.rs b/nomen/src/subcommands/mod.rs index 5e35954..4e8dad4 100644 --- a/nomen/src/subcommands/mod.rs +++ b/nomen/src/subcommands/mod.rs @@ -75,5 +75,5 @@ pub(crate) async fn rebroadcast(config: &Config, pool: &SqlitePool) -> anyhow::R pub(crate) async fn publish(config: &Config, pool: &SqlitePool) -> anyhow::Result<()> { println!("Publishing full relay index"); - index::events::relay_index::publish(config, pool).await + index::events::relay_index::publish(config, pool, false).await }