Skip to content

Commit

Permalink
Break on empty events when loading from remote (#2376)
Browse files Browse the repository at this point in the history
currently we only stop querying for events when the provider no longer returns a continuation token. this pr adds an extra safety net to stop immediately when there are no more events being returned.

though the spec mentions explicitly that the token Should not appear if there are no more pages. but it doesn't mention exactly how the token should behave with pending block as the list of events in the pending block could still grow.

there could be a case where someone calls getEvents with the the to block sets to=pending. if they already reach the end of the pending block during the first call, yet the block could still emit new events. but if the returned continuation token is nil, then if the user wants to continue from the last events in the first call, they couldn't and had to start from the beginning again.
  • Loading branch information
kariy authored Sep 1, 2024
1 parent f62acf2 commit 1d95782
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/dojo-world/src/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,14 @@ async fn get_events<P: Provider + Send + Sync>(
loop {
let res =
provider.get_events(filter.clone(), continuation_token, DEFAULT_CHUNK_SIZE).await?;

continuation_token = res.continuation_token;
events.extend(res.events);

// stop when there are no more events being returned
if res.events.is_empty() {
break;
} else {
events.extend(res.events);
}

if continuation_token.is_none() {
break;
Expand Down

0 comments on commit 1d95782

Please sign in to comment.