diff --git a/bin/torii/src/main.rs b/bin/torii/src/main.rs index 374cce2829..b1447970de 100644 --- a/bin/torii/src/main.rs +++ b/bin/torii/src/main.rs @@ -20,7 +20,9 @@ use clap::{ArgAction, Parser}; use dojo_metrics::{metrics_process, prometheus_exporter}; use dojo_utils::parse::{parse_socket_address, parse_url}; use dojo_world::contracts::world::WorldContractReader; -use sqlx::sqlite::{SqliteConnectOptions, SqlitePoolOptions}; +use sqlx::sqlite::{ + SqliteAutoVacuum, SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions, SqliteSynchronous, +}; use sqlx::SqlitePool; use starknet::core::types::Felt; use starknet::providers::jsonrpc::HttpTransport; @@ -153,19 +155,15 @@ async fn main() -> anyhow::Result<()> { }) .expect("Error setting Ctrl-C handler"); - let database_url = format!("sqlite:{}", &args.database); - let options = - SqliteConnectOptions::from_str(&database_url)?.create_if_missing(true).with_regexp(); - let pool = SqlitePoolOptions::new() - .min_connections(1) - .max_connections(5) - .connect_with(options) - .await?; + let mut options = + SqliteConnectOptions::from_str(&args.database)?.create_if_missing(true).with_regexp(); + + // Performance settings + options = options.auto_vacuum(SqliteAutoVacuum::None); + options = options.journal_mode(SqliteJournalMode::Wal); + options = options.synchronous(SqliteSynchronous::Normal); - // Disable auto-vacuum - sqlx::query("PRAGMA auto_vacuum = NONE;").execute(&pool).await?; - sqlx::query("PRAGMA journal_mode = WAL;").execute(&pool).await?; - sqlx::query("PRAGMA synchronous = NORMAL;").execute(&pool).await?; + let pool = SqlitePoolOptions::new().min_connections(1).connect_with(options).await?; // Set the number of threads based on CPU count let cpu_count = std::thread::available_parallelism().unwrap().get();