Skip to content

Commit

Permalink
fix: publis command should not use queue
Browse files Browse the repository at this point in the history
  • Loading branch information
ursuscamp committed Nov 23, 2023
1 parent 7a27d61 commit 20489c0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
14 changes: 13 additions & 1 deletion nomen/src/db/relay_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<Name>> {
let results = sqlx::query_as::<_, Name>(
Expand All @@ -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<Vec<Name>> {
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,
Expand Down
8 changes: 6 additions & 2 deletions nomen/src/subcommands/index/events/relay_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(());
}
Expand All @@ -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.");

Expand Down
2 changes: 1 addition & 1 deletion nomen/src/subcommands/index/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
2 changes: 1 addition & 1 deletion nomen/src/subcommands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 20489c0

Please sign in to comment.