Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Sep 19, 2024
1 parent be67c5c commit 51c654b
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions crates/torii/grpc/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -229,10 +229,10 @@ impl DojoWorld {

let mut all_entities = Vec::new();

// Start a transaction
let mut tx = self.pool.begin().await?;

// Create a temporary table to store entity IDs
// Create a temporary table to store entity IDs due to them potentially exceeding
// SQLite's parameters limit which is 999
sqlx::query(
"CREATE TEMPORARY TABLE temp_entity_ids (id TEXT PRIMARY KEY, model_group TEXT)",
)
Expand Down Expand Up @@ -295,10 +295,8 @@ impl DojoWorld {
all_entities.extend(group_entities?);
}

// Drop the temporary table
sqlx::query("DROP TABLE temp_entity_ids").execute(&mut *tx).await?;

// Commit the transaction
tx.commit().await?;

Ok(all_entities)
Expand Down Expand Up @@ -599,7 +597,6 @@ impl DojoWorld {
arrays_rows.insert(name, rows);
}

// Use Rayon to parallelize the mapping of rows to entities
let arrays_rows = Arc::new(arrays_rows);
let entities_collection: Result<Vec<_>, Error> = db_entities
.par_iter()
Expand Down Expand Up @@ -870,15 +867,17 @@ fn map_row_to_entity(

// this builds a sql safe regex pattern to match against for keys
fn build_keys_pattern(clause: &proto::types::KeysClause) -> Result<String, Error> {
const KEY_PATTERN: &str = "0x[0-9a-fA-F]+";

let keys = if clause.keys.is_empty() {
vec!["0x[0-9a-fA-F]+".to_string()]
vec![KEY_PATTERN.to_string()]
} else {
clause
.keys
.iter()
.map(|bytes| {
if bytes.is_empty() {
return Ok("0x[0-9a-fA-F]+".to_string());
return Ok(KEY_PATTERN.to_string());
}
Ok(format!("{:#x}", Felt::from_bytes_be_slice(bytes)))
})
Expand All @@ -887,7 +886,7 @@ fn build_keys_pattern(clause: &proto::types::KeysClause) -> Result<String, Error
let mut keys_pattern = format!("^{}", keys.join("/"));

if clause.pattern_matching == proto::types::PatternMatching::VariableLen as i32 {
keys_pattern += "(/0x[0-9a-fA-F]+)*";
keys_pattern += &format!("({})*", KEY_PATTERN);
}
keys_pattern += "/$";

Expand Down

0 comments on commit 51c654b

Please sign in to comment.