-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(torii): add world block and instrument queries #2796
Merged
ponderingdemocritus
merged 4 commits into
main
from
feat/index-from-eternum-start-block
Dec 12, 2024
+60
−3
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -263,25 +263,36 @@ | |
dont_include_hashed_keys: bool, | ||
order_by: Option<&str>, | ||
) -> Result<Vec<proto::types::Entity>, Error> { | ||
tracing::debug!( | ||
"Fetching entities from table {table} with {} entity/model pairs", | ||
entities.len() | ||
); | ||
let start = std::time::Instant::now(); | ||
|
||
// Group entities by their model combinations | ||
let mut model_groups: HashMap<String, Vec<String>> = HashMap::new(); | ||
for (entity_id, models_str) in entities { | ||
model_groups.entry(models_str).or_default().push(entity_id); | ||
} | ||
tracing::debug!("Grouped into {} distinct model combinations", model_groups.len()); | ||
|
||
let mut all_entities = Vec::new(); | ||
|
||
let mut tx = self.pool.begin().await?; | ||
tracing::debug!("Started database transaction"); | ||
|
||
// Create a temporary table to store entity IDs due to them potentially exceeding | ||
// SQLite's parameters limit which is 999 | ||
let temp_table_start = std::time::Instant::now(); | ||
sqlx::query( | ||
"CREATE TEMPORARY TABLE temp_entity_ids (id TEXT PRIMARY KEY, model_group TEXT)", | ||
) | ||
.execute(&mut *tx) | ||
.await?; | ||
tracing::debug!("Created temporary table in {:?}", temp_table_start.elapsed()); | ||
|
||
// Insert all entity IDs into the temporary table | ||
let insert_start = std::time::Instant::now(); | ||
for (model_ids, entity_ids) in &model_groups { | ||
for chunk in entity_ids.chunks(999) { | ||
let placeholders = chunk.iter().map(|_| "(?, ?)").collect::<Vec<_>>().join(","); | ||
|
@@ -296,8 +307,14 @@ | |
query.execute(&mut *tx).await?; | ||
} | ||
} | ||
tracing::debug!( | ||
"Inserted all entity IDs into temporary table in {:?}", | ||
insert_start.elapsed() | ||
); | ||
|
||
for (models_str, _) in model_groups { | ||
let query_start = std::time::Instant::now(); | ||
for (models_str, entity_ids) in &model_groups { | ||
tracing::debug!("Processing model group with {} entities", entity_ids.len()); | ||
Comment on lines
+315
to
+317
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add error logging for model processing. The model group processing lacks error logging. Consider adding error logs to help with debugging. let query_start = std::time::Instant::now();
for (models_str, entity_ids) in &model_groups {
- tracing::debug!("Processing model group with {} entities", entity_ids.len());
+ tracing::info!("Processing model group with {} entities", entity_ids.len());
+ if let Err(e) = process_model_group(models_str, entity_ids).await {
+ tracing::error!("Failed to process model group: {}", e);
+ return Err(e);
+ }
|
||
let model_ids = | ||
models_str.split(',').map(|id| Felt::from_str(id).unwrap()).collect::<Vec<_>>(); | ||
let schemas = | ||
|
@@ -325,10 +342,15 @@ | |
|
||
all_entities.extend(group_entities?); | ||
} | ||
tracing::debug!("Processed all model groups in {:?}", query_start.elapsed()); | ||
|
||
sqlx::query("DROP TABLE temp_entity_ids").execute(&mut *tx).await?; | ||
tracing::debug!("Dropped temporary table"); | ||
|
||
tx.commit().await?; | ||
tracing::debug!("Committed transaction"); | ||
|
||
tracing::debug!("Total fetch_entities operation took {:?}", start.elapsed()); | ||
|
||
Ok(all_entities) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
world_address = "0x6a9e4c6f0799160ea8ddc43ff982a5f83d7f633e9732ce42701de1288ff705f" | ||
rpc = "https://api.cartridge.gg/x/starknet/mainnet" | ||
explorer = false | ||
|
||
[indexing] | ||
events_chunk_size = 1024 | ||
blocks_chunk_size = 1024000 | ||
pending = true | ||
polling_interval = 500 | ||
max_concurrent_tasks = 100 | ||
transactions = false | ||
contracts = ["ERC721:0x57675b9c0bd62b096a2e15502a37b290fa766ead21c33eda42993e48a714b80", "ERC721:0x7ae27a31bb6526e3de9cf02f081f6ce0615ac12a6d7b85ee58b8ad7947a2809", "ERC20:0x124aeb495b947201f5fac96fd1138e326ad86195b98df6dec9009158a533b49"] | ||
namespaces = [] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohayo sensei! Document the significance of block number 948000.
The hardcoded block number
948000
lacks context. This magic number should be documented or moved to a configuration value.📝 Committable suggestion