Skip to content

Commit

Permalink
refactor(torii-core): upgrade model silent if not in namespace (#2688)
Browse files Browse the repository at this point in the history
  • Loading branch information
Larkooo authored Nov 14, 2024
1 parent 6af7e92 commit 51d80cf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 22 deletions.
15 changes: 9 additions & 6 deletions crates/torii/core/src/processors/store_del_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};
use crate::sql::Sql;
Expand Down Expand Up @@ -55,12 +55,15 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

info!(
Expand Down
15 changes: 9 additions & 6 deletions crates/torii/core/src/processors/store_set_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};
use crate::sql::utils::felts_to_sql_string;
Expand Down Expand Up @@ -56,12 +56,15 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

info!(
Expand Down
15 changes: 9 additions & 6 deletions crates/torii/core/src/processors/store_update_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::world::WorldContractReader;
use starknet::core::types::Event;
use starknet::providers::Provider;
use tracing::info;
use tracing::{debug, info};

use super::{EventProcessor, EventProcessorConfig};
use crate::sql::Sql;
Expand Down Expand Up @@ -59,12 +59,15 @@ where
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) => {
if e.to_string().contains("no rows") {
return Ok(());
}
return Err(e);
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

info!(
Expand Down
18 changes: 16 additions & 2 deletions crates/torii/core/src/processors/upgrade_event.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Error, Ok, Result};
use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::model::ModelReader;
Expand Down Expand Up @@ -56,7 +56,21 @@ where

// Called model here by language, but it's an event. Torii rework will make clear
// distinction.
let model = db.model(event.selector).await?;

// If the model does not exist, silently ignore it.
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};
let name = model.name;
let namespace = model.namespace;
let prev_schema = model.schema;
Expand Down
18 changes: 16 additions & 2 deletions crates/torii/core/src/processors/upgrade_model.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use anyhow::{Error, Ok, Result};
use anyhow::{Error, Result};
use async_trait::async_trait;
use dojo_world::contracts::abigen::world::Event as WorldEvent;
use dojo_world::contracts::model::ModelReader;
Expand Down Expand Up @@ -54,7 +54,21 @@ where
}
};

let model = db.model(event.selector).await?;
// If the model does not exist, silently ignore it.
// This can happen if only specific namespaces are indexed.
let model = match db.model(event.selector).await {
Ok(m) => m,
Err(e) if e.to_string().contains("no rows") => {
debug!(
target: LOG_TARGET,
selector = %event.selector,
"Model does not exist, skipping."
);
return Ok(());
}
Err(e) => return Err(e),
};

let name = model.name;
let namespace = model.namespace;
let prev_schema = model.schema;
Expand Down

0 comments on commit 51d80cf

Please sign in to comment.