From f2d33b1de80affc469c6b2a95835a17d39706ffa Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 14 Nov 2024 15:06:07 +0700 Subject: [PATCH 1/4] refactor(torii-core): upgrade model silent if not in namespace --- crates/torii/core/src/processors/upgrade_event.rs | 13 ++++++++++++- crates/torii/core/src/processors/upgrade_model.rs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/crates/torii/core/src/processors/upgrade_event.rs b/crates/torii/core/src/processors/upgrade_event.rs index 8479d9ab05..b982950c62 100644 --- a/crates/torii/core/src/processors/upgrade_event.rs +++ b/crates/torii/core/src/processors/upgrade_event.rs @@ -56,7 +56,18 @@ 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") { + return Ok(()); + } + return Err(e); + } + }; let name = model.name; let namespace = model.namespace; let prev_schema = model.schema; diff --git a/crates/torii/core/src/processors/upgrade_model.rs b/crates/torii/core/src/processors/upgrade_model.rs index 403e1e17fd..8a5e50530c 100644 --- a/crates/torii/core/src/processors/upgrade_model.rs +++ b/crates/torii/core/src/processors/upgrade_model.rs @@ -54,7 +54,18 @@ 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") { + return Ok(()); + } + return Err(e); + } + }; + let name = model.name; let namespace = model.namespace; let prev_schema = model.schema; From 60f49d6ad587de2d2341016c6d1fff5e2489d64a Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 14 Nov 2024 15:06:42 +0700 Subject: [PATCH 2/4] fix --- crates/torii/core/src/processors/upgrade_event.rs | 2 +- crates/torii/core/src/processors/upgrade_model.rs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/torii/core/src/processors/upgrade_event.rs b/crates/torii/core/src/processors/upgrade_event.rs index b982950c62..4e6f1730ed 100644 --- a/crates/torii/core/src/processors/upgrade_event.rs +++ b/crates/torii/core/src/processors/upgrade_event.rs @@ -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; diff --git a/crates/torii/core/src/processors/upgrade_model.rs b/crates/torii/core/src/processors/upgrade_model.rs index 8a5e50530c..8400b17b8d 100644 --- a/crates/torii/core/src/processors/upgrade_model.rs +++ b/crates/torii/core/src/processors/upgrade_model.rs @@ -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; @@ -65,7 +65,7 @@ where return Err(e); } }; - + let name = model.name; let namespace = model.namespace; let prev_schema = model.schema; From 56e12d47f516c1bca662023ef27a719dc4f6c123 Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 14 Nov 2024 16:18:50 +0700 Subject: [PATCH 3/4] logi n debug --- .../core/src/processors/store_del_record.rs | 17 ++++++++++------- .../core/src/processors/store_set_record.rs | 17 ++++++++++------- .../core/src/processors/store_update_record.rs | 17 ++++++++++------- .../torii/core/src/processors/upgrade_event.rs | 15 +++++++++------ .../torii/core/src/processors/upgrade_model.rs | 15 +++++++++------ 5 files changed, 48 insertions(+), 33 deletions(-) diff --git a/crates/torii/core/src/processors/store_del_record.rs b/crates/torii/core/src/processors/store_del_record.rs index cf9c79f79f..e9f2fb3b8e 100644 --- a/crates/torii/core/src/processors/store_del_record.rs +++ b/crates/torii/core/src/processors/store_del_record.rs @@ -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; @@ -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!( diff --git a/crates/torii/core/src/processors/store_set_record.rs b/crates/torii/core/src/processors/store_set_record.rs index 16943cb1fb..4c67cf7301 100644 --- a/crates/torii/core/src/processors/store_set_record.rs +++ b/crates/torii/core/src/processors/store_set_record.rs @@ -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; @@ -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!( diff --git a/crates/torii/core/src/processors/store_update_record.rs b/crates/torii/core/src/processors/store_update_record.rs index c0179c7946..fb1d46cb2c 100644 --- a/crates/torii/core/src/processors/store_update_record.rs +++ b/crates/torii/core/src/processors/store_update_record.rs @@ -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; @@ -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!( diff --git a/crates/torii/core/src/processors/upgrade_event.rs b/crates/torii/core/src/processors/upgrade_event.rs index 4e6f1730ed..a4a03a7ec1 100644 --- a/crates/torii/core/src/processors/upgrade_event.rs +++ b/crates/torii/core/src/processors/upgrade_event.rs @@ -61,12 +61,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), }; let name = model.name; let namespace = model.namespace; diff --git a/crates/torii/core/src/processors/upgrade_model.rs b/crates/torii/core/src/processors/upgrade_model.rs index 8400b17b8d..d7c55b7bc4 100644 --- a/crates/torii/core/src/processors/upgrade_model.rs +++ b/crates/torii/core/src/processors/upgrade_model.rs @@ -58,12 +58,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), }; let name = model.name; From db93dbacb5e5d5330e6a118abfdd3fabe1241f4b Mon Sep 17 00:00:00 2001 From: Nasr Date: Thu, 14 Nov 2024 16:19:00 +0700 Subject: [PATCH 4/4] fmt --- crates/torii/core/src/processors/store_del_record.rs | 2 +- crates/torii/core/src/processors/store_set_record.rs | 2 +- crates/torii/core/src/processors/store_update_record.rs | 2 +- crates/torii/core/src/processors/upgrade_event.rs | 2 +- crates/torii/core/src/processors/upgrade_model.rs | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/torii/core/src/processors/store_del_record.rs b/crates/torii/core/src/processors/store_del_record.rs index e9f2fb3b8e..f6b34db24a 100644 --- a/crates/torii/core/src/processors/store_del_record.rs +++ b/crates/torii/core/src/processors/store_del_record.rs @@ -62,7 +62,7 @@ where "Model does not exist, skipping." ); return Ok(()); - }, + } Err(e) => return Err(e), }; diff --git a/crates/torii/core/src/processors/store_set_record.rs b/crates/torii/core/src/processors/store_set_record.rs index 4c67cf7301..cc602fd868 100644 --- a/crates/torii/core/src/processors/store_set_record.rs +++ b/crates/torii/core/src/processors/store_set_record.rs @@ -63,7 +63,7 @@ where "Model does not exist, skipping." ); return Ok(()); - }, + } Err(e) => return Err(e), }; diff --git a/crates/torii/core/src/processors/store_update_record.rs b/crates/torii/core/src/processors/store_update_record.rs index fb1d46cb2c..f94920e411 100644 --- a/crates/torii/core/src/processors/store_update_record.rs +++ b/crates/torii/core/src/processors/store_update_record.rs @@ -66,7 +66,7 @@ where "Model does not exist, skipping." ); return Ok(()); - }, + } Err(e) => return Err(e), }; diff --git a/crates/torii/core/src/processors/upgrade_event.rs b/crates/torii/core/src/processors/upgrade_event.rs index a4a03a7ec1..da329501af 100644 --- a/crates/torii/core/src/processors/upgrade_event.rs +++ b/crates/torii/core/src/processors/upgrade_event.rs @@ -68,7 +68,7 @@ where "Model does not exist, skipping." ); return Ok(()); - }, + } Err(e) => return Err(e), }; let name = model.name; diff --git a/crates/torii/core/src/processors/upgrade_model.rs b/crates/torii/core/src/processors/upgrade_model.rs index d7c55b7bc4..0b7e36820d 100644 --- a/crates/torii/core/src/processors/upgrade_model.rs +++ b/crates/torii/core/src/processors/upgrade_model.rs @@ -65,7 +65,7 @@ where "Model does not exist, skipping." ); return Ok(()); - }, + } Err(e) => return Err(e), };