Skip to content

Commit

Permalink
refactor(torii): max conns to tasks & dont use sqlite acquire (#2911)
Browse files Browse the repository at this point in the history
* refactor(torii): max conns to tasks & dont use sqlite acquire

* fmt
  • Loading branch information
Larkooo authored Jan 15, 2025
1 parent a8af3d6 commit d50627b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
7 changes: 5 additions & 2 deletions crates/torii/runner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,11 @@ impl Runner {
options = options.journal_mode(SqliteJournalMode::Wal);
options = options.synchronous(SqliteSynchronous::Normal);

let pool =
SqlitePoolOptions::new().min_connections(1).connect_with(options.clone()).await?;
let pool = SqlitePoolOptions::new()
.min_connections(1)
.max_connections(self.args.indexing.max_concurrent_tasks as u32)
.connect_with(options.clone())
.await?;

let readonly_options = options.read_only(true);
let readonly_pool = SqlitePoolOptions::new()
Expand Down
13 changes: 2 additions & 11 deletions crates/torii/sqlite/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use dojo_types::schema::{Struct, Ty};
use dojo_world::config::WorldMetadata;
use dojo_world::contracts::abigen::model::Layout;
use dojo_world::contracts::naming::compute_selector_from_names;
use sqlx::pool::PoolConnection;
use sqlx::{Pool, Sqlite};
use starknet::core::types::{Event, Felt, InvokeTransaction, Transaction};
use starknet_crypto::poseidon_hash_many;
Expand Down Expand Up @@ -173,18 +172,17 @@ impl Sql {
}

pub async fn cursors(&self) -> Result<Cursors> {
let mut conn: PoolConnection<Sqlite> = self.pool.acquire().await?;
let cursors = sqlx::query_as::<_, (String, String)>(
"SELECT contract_address, last_pending_block_contract_tx FROM contracts WHERE \
last_pending_block_contract_tx IS NOT NULL",
)
.fetch_all(&mut *conn)
.fetch_all(&self.pool)
.await?;

let (head, last_pending_block_tx) = sqlx::query_as::<_, (Option<i64>, Option<String>)>(
"SELECT head, last_pending_block_tx FROM contracts WHERE 1=1",
)
.fetch_one(&mut *conn)
.fetch_one(&self.pool)
.await?;

let head = head.map(|h| h.try_into().expect("doesn't fit in u64"));
Expand Down Expand Up @@ -514,13 +512,6 @@ impl Sql {
self.model_cache.model(&selector).await.map_err(|e| e.into())
}

pub async fn entities(&self, model: String) -> Result<Vec<Vec<Felt>>> {
let query = sqlx::query_as::<_, (i32, String, String)>("SELECT * FROM ?").bind(model);
let mut conn: PoolConnection<Sqlite> = self.pool.acquire().await?;
let mut rows = query.fetch_all(&mut *conn).await?;
Ok(rows.drain(..).map(|row| serde_json::from_str(&row.2).unwrap()).collect())
}

pub fn store_transaction(
&mut self,
transaction: &Transaction,
Expand Down

0 comments on commit d50627b

Please sign in to comment.