Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo committed Sep 25, 2024
1 parent 9314438 commit f9a136f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 45 deletions.
22 changes: 8 additions & 14 deletions crates/torii/core/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,15 @@ impl<P: Provider + Send + Sync + std::fmt::Debug + 'static> Engine<P> {
}

match self.process(fetch_result).await {
Ok(()) => {
let _ = self.db.executor.send(QueryMessage {
statement: "".to_string(),
arguments: vec![],
query_type: QueryType::Execute,
});
Ok(()) => self.db.execute()?,
Err(e) => {
error!(target: LOG_TARGET, error = %e, "Processing fetched data.");
erroring_out = true;
sleep(backoff_delay).await;
if backoff_delay < max_backoff_delay {
backoff_delay *= 2;
}
}
Err(e) => {
error!(target: LOG_TARGET, error = %e, "Processing fetched data.");
erroring_out = true;
sleep(backoff_delay).await;
if backoff_delay < max_backoff_delay {
backoff_delay *= 2;
}
}
}
debug!(target: LOG_TARGET, duration = ?instant.elapsed(), "Processed fetched data.");
}
Expand Down
2 changes: 1 addition & 1 deletion crates/torii/core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod cache;
pub mod engine;
pub mod error;
pub mod executor;
pub mod model;
pub mod processors;
pub mod executor;
pub mod simple_broker;
pub mod sql;
pub mod types;
Expand Down
3 changes: 1 addition & 2 deletions crates/torii/core/src/processors/metadata_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ where
async fn try_retrieve(mut db: Sql, resource: Felt, uri_str: String) {
match metadata(uri_str.clone()).await {
Ok((metadata, icon_img, cover_img)) => {
db.update_metadata(&resource, &uri_str, &metadata, &icon_img, &cover_img)
.unwrap();
db.update_metadata(&resource, &uri_str, &metadata, &icon_img, &cover_img).unwrap();
info!(
target: LOG_TARGET,
resource = %format!("{:#x}", resource),
Expand Down
65 changes: 38 additions & 27 deletions crates/torii/core/src/sql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ impl Sql {
executor: UnboundedSender<QueryMessage>,
) -> Result<Self> {
executor.send(QueryMessage {
statement: "INSERT OR IGNORE INTO contracts (id, contract_address, contract_type) VALUES (?, ?, \
?)".to_string(),
statement: "INSERT OR IGNORE INTO contracts (id, contract_address, contract_type) \
VALUES (?, ?, ?)"
.to_string(),
arguments: vec![
Argument::FieldElement(world_address),
Argument::FieldElement(world_address),
Expand All @@ -54,8 +55,9 @@ impl Sql {
})?;

executor.send(QueryMessage {
statement: "INSERT OR IGNORE INTO contracts (id, contract_address, contract_type) VALUES (?, ?, \
?)".to_string(),
statement: "INSERT OR IGNORE INTO contracts (id, contract_address, contract_type) \
VALUES (?, ?, ?)"
.to_string(),
arguments: vec![
Argument::FieldElement(world_address),
Argument::FieldElement(world_address),
Expand Down Expand Up @@ -107,7 +109,10 @@ impl Sql {
Ok(())
}

pub fn set_last_pending_block_world_tx(&mut self, last_pending_block_world_tx: Option<Felt>) -> Result<()> {
pub fn set_last_pending_block_world_tx(
&mut self,
last_pending_block_world_tx: Option<Felt>,
) -> Result<()> {
let last_pending_block_world_tx = if let Some(f) = last_pending_block_world_tx {
Argument::String(format!("{:#x}", f))
} else {
Expand Down Expand Up @@ -261,9 +266,13 @@ impl Sql {
})?;

self.executor.send(QueryMessage {
statement: "INSERT INTO entity_model (entity_id, model_id) VALUES (?, ?) ON CONFLICT(entity_id, \
model_id) DO NOTHING".to_string(),
arguments: vec![Argument::String(entity_id.clone()), Argument::String(model_id.clone())],
statement: "INSERT INTO entity_model (entity_id, model_id) VALUES (?, ?) ON \
CONFLICT(entity_id, model_id) DO NOTHING"
.to_string(),
arguments: vec![
Argument::String(entity_id.clone()),
Argument::String(model_id.clone()),
],
query_type: QueryType::Other,
})?;

Expand Down Expand Up @@ -318,9 +327,13 @@ impl Sql {
query_type: QueryType::EventMessage(entity.clone()),
})?;
self.executor.send(QueryMessage {
statement: "INSERT INTO event_model (entity_id, model_id) VALUES (?, ?) ON CONFLICT(entity_id, \
model_id) DO NOTHING".to_string(),
arguments: vec![Argument::String(entity_id.clone()), Argument::String(model_id.clone())],
statement: "INSERT INTO event_model (entity_id, model_id) VALUES (?, ?) ON \
CONFLICT(entity_id, model_id) DO NOTHING"
.to_string(),
arguments: vec![
Argument::String(entity_id.clone()),
Argument::String(model_id.clone()),
],
query_type: QueryType::Other,
})?;

Expand Down Expand Up @@ -373,11 +386,10 @@ impl Sql {
let executed_at = Argument::String(utc_dt_string_from_timestamp(block_timestamp));

self.executor.send(QueryMessage {
statement:
"INSERT INTO metadata (id, uri, executed_at) VALUES (?, ?, ?) ON CONFLICT(id) DO \
UPDATE SET id=excluded.id, executed_at=excluded.executed_at, \
updated_at=CURRENT_TIMESTAMP"
.to_string(),
statement: "INSERT INTO metadata (id, uri, executed_at) VALUES (?, ?, ?) ON \
CONFLICT(id) DO UPDATE SET id=excluded.id, \
executed_at=excluded.executed_at, updated_at=CURRENT_TIMESTAMP"
.to_string(),
arguments: vec![resource, uri, executed_at],
query_type: QueryType::Other,
})?;
Expand Down Expand Up @@ -472,9 +484,10 @@ impl Sql {
};

self.executor.send(QueryMessage {
statement: "INSERT OR IGNORE INTO transactions (id, transaction_hash, sender_address, calldata, \
max_fee, signature, nonce, transaction_type, executed_at) VALUES (?, ?, ?, ?, ?, ?, \
?, ?, ?)".to_string(),
statement: "INSERT OR IGNORE INTO transactions (id, transaction_hash, sender_address, \
calldata, max_fee, signature, nonce, transaction_type, executed_at) \
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"
.to_string(),
arguments: vec![
id,
transaction_hash,
Expand Down Expand Up @@ -506,8 +519,9 @@ impl Sql {
let executed_at = Argument::String(utc_dt_string_from_timestamp(block_timestamp));

self.executor.send(QueryMessage {
statement: "INSERT OR IGNORE INTO events (id, keys, data, transaction_hash, executed_at) VALUES \
(?, ?, ?, ?, ?) RETURNING *".to_string(),
statement: "INSERT OR IGNORE INTO events (id, keys, data, transaction_hash, \
executed_at) VALUES (?, ?, ?, ?, ?) RETURNING *"
.to_string(),
arguments: vec![id, keys, data, hash, executed_at],
query_type: QueryType::StoreEvent,
})?;
Expand Down Expand Up @@ -608,7 +622,8 @@ impl Sql {

let update_members = |members: &[Member],
executor: &mut UnboundedSender<QueryMessage>,
indexes: &Vec<i64>| -> Result<()> {
indexes: &Vec<i64>|
-> Result<()> {
let table_id = path.join("$");
let mut columns = vec![
"id".to_string(),
Expand Down Expand Up @@ -719,11 +734,7 @@ impl Sql {
Ty::Enum(e) => {
if e.options.iter().all(
|o| {
if let Ty::Tuple(t) = &o.ty {
t.is_empty()
} else {
false
}
if let Ty::Tuple(t) = &o.ty { t.is_empty() } else { false }
},
) {
return Ok(());
Expand Down
3 changes: 2 additions & 1 deletion crates/torii/graphql/src/tests/subscription_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@ mod tests {
},
Felt::ZERO,
block_timestamp,
).unwrap();
)
.unwrap();
db.execute().unwrap();

tx.send(()).await.unwrap();
Expand Down

0 comments on commit f9a136f

Please sign in to comment.