Skip to content
This repository has been archived by the owner on Jun 19, 2024. It is now read-only.

Commit

Permalink
feat: skip the index creation in the database if not needed (#88)
Browse files Browse the repository at this point in the history
  • Loading branch information
rllola authored Feb 5, 2024
1 parent 6706265 commit a324033
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/bin/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,5 @@ async fn main() -> Result<(), Error> {
start_metrics_server(cfg.prometheus_config()).await?;

info!("Starting indexer");
start_indexing(db, cfg.indexer_config()).await
start_indexing(db, cfg.indexer_config(), cfg.database.create_index).await
}
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ pub struct DatabaseConfig {
pub dbname: String,
// The limit in seconds to wait for a ready database connection
pub connection_timeout: Option<u64>,
// Give the option to skip the index creation
pub create_index: bool,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -111,6 +113,7 @@ impl Default for DatabaseConfig {
password: "wow".to_owned(),
dbname: "blockchain".to_owned(),
connection_timeout: None,
create_index: true,
}
}
}
Expand All @@ -135,6 +138,8 @@ pub struct CliSettings {
pub database_dbname: String,
#[clap(long, env)]
pub database_connection_timeout: Option<u64>,
#[clap(long, env, default_value = "true")]
pub database_create_index: bool,
#[clap(long, env, default_value = TENDERMINT_ADDR)]
pub indexer_tendermint_addr: String,
#[clap(long, env, action=ArgAction::SetFalse)]
Expand Down Expand Up @@ -185,6 +190,7 @@ impl From<CliSettings> for Settings {
password: value.database_password,
dbname: value.database_dbname,
connection_timeout: value.database_connection_timeout,
create_index: value.database_create_index,
},
server: ServerConfig {
serve_at: value.server_serve_at,
Expand Down
15 changes: 11 additions & 4 deletions src/indexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ fn blocks_stream(
///
/// `config` The configuration containing required information used to connect to namada node
/// to retrieve blocks from.
pub async fn start_indexing(db: Database, config: &IndexerConfig) -> Result<(), Error> {
pub async fn start_indexing(
db: Database,
config: &IndexerConfig,
create_index: bool,
) -> Result<(), Error> {
info!("***** Starting indexer *****");

/********************
Expand Down Expand Up @@ -235,10 +239,13 @@ pub async fn start_indexing(db: Database, config: &IndexerConfig) -> Result<(),
// create indexes if they have not been created yet
if !has_indexes && latest_block.block.header.height == height {
info!("We are synced!");
info!("Creating indexes");
db.create_indexes().await?;

info!("Indexing done");
if create_index {
info!("Creating indexes");
db.create_indexes().await?;

info!("Indexing done");
}
}

current_height += 1;
Expand Down

0 comments on commit a324033

Please sign in to comment.