Skip to content

Commit

Permalink
feat(torii-core): specify namespaces to exclusively index
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Nov 14, 2024
1 parent 4671d9c commit d87c399
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
3 changes: 2 additions & 1 deletion bin/torii/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,8 @@ async fn main() -> anyhow::Result<()> {
polling_interval: Duration::from_millis(args.indexing.polling_interval),
flags,
event_processor_config: EventProcessorConfig {
historical_events: args.events.historical.unwrap_or_default().into_iter().collect(),
historical_events: args.events.historical.into_iter().collect(),
namespaces: args.indexing.namespaces.into_iter().collect(),
},
},
shutdown_tx.clone(),
Expand Down
7 changes: 2 additions & 5 deletions crates/torii/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ mod test {
assert_eq!(torii_args.rpc, Url::parse("http://0.0.0.0:6060").unwrap());
assert_eq!(torii_args.db_dir, Some(PathBuf::from("/tmp/torii-test2")));
assert!(!torii_args.events.raw);
assert_eq!(torii_args.events.historical, Some(vec!["a-A".to_string()]));
assert_eq!(torii_args.events.historical, vec!["a-A".to_string()]);
assert_eq!(torii_args.server, ServerOptions::default());
}

Expand Down Expand Up @@ -282,10 +282,7 @@ mod test {
assert_eq!(torii_args.rpc, Url::parse("http://0.0.0.0:2222").unwrap());
assert_eq!(torii_args.db_dir, Some(PathBuf::from("/tmp/torii-test")));
assert!(!torii_args.events.raw);
assert_eq!(
torii_args.events.historical,
Some(vec!["ns-E".to_string(), "ns-EH".to_string()])
);
assert_eq!(torii_args.events.historical, vec!["ns-E".to_string(), "ns-EH".to_string()]);
assert_eq!(torii_args.indexing.events_chunk_size, 9999);
assert_eq!(torii_args.indexing.blocks_chunk_size, 10240);
assert!(torii_args.indexing.index_pending);
Expand Down
13 changes: 11 additions & 2 deletions crates/torii/cli/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ pub struct IndexingOptions {
)]
#[serde(deserialize_with = "deserialize_contracts")]
pub contracts: Vec<Contract>,

/// Namespaces to index
#[arg(
long = "indexing.namespaces",
value_delimiter = ',',
help = "The namespaces of the world that torii should index. If empty, all namespaces will be indexed."
)]
pub namespaces: Vec<String>,
}

impl Default for IndexingOptions {
Expand All @@ -150,6 +158,7 @@ impl Default for IndexingOptions {
contracts: vec![],
polling_interval: DEFAULT_POLLING_INTERVAL,
max_concurrent_tasks: DEFAULT_MAX_CONCURRENT_TASKS,
namespaces: vec![],
}
}
}
Expand All @@ -168,12 +177,12 @@ pub struct EventsOptions {
value_delimiter = ',',
help = "Event messages that are going to be treated as historical during indexing."
)]
pub historical: Option<Vec<String>>,
pub historical: Vec<String>,
}

impl Default for EventsOptions {
fn default() -> Self {
Self { raw: true, historical: None }
Self { raw: true, historical: vec![] }
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/torii/core/src/processors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const ENTITY_ID_INDEX: usize = 1;
#[derive(Clone, Debug, Default)]
pub struct EventProcessorConfig {
pub historical_events: HashSet<String>,
pub namespaces: HashSet<String>,
}

#[async_trait]
Expand Down

0 comments on commit d87c399

Please sign in to comment.