Skip to content

Commit

Permalink
cometindex: avoid unnecessary rollbacks (#5106)
Browse files Browse the repository at this point in the history
We created a transaction too early in the previous version of the code,
which meant that in the common case of skipping a batch of transactions,
we would create the transaction before checking if we need to do
anything.

Smoke tests should be sufficient to test.

## Checklist before requesting a review

- [x] I have added guiding text to explain how a reviewer should test
these changes.

- [x] If this code contains consensus-breaking changes, I have added the
"consensus-breaking" label. Otherwise, I declare my belief that there
are not consensus-breaking changes, for the following reason:

  > indexing only
  • Loading branch information
cronokirby authored Feb 27, 2025
1 parent 4d683f5 commit 98fb73d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/util/cometindex/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ async fn catchup(
tracing::info!(?name, "already initialized");
}
while let Some(mut events) = rx.recv().await {
let mut dbtx = state_cp.begin_transaction().await?;
// We only ever want to index events past our current height.
// We might receive a batch with more events because other indices are behind us.
events.start_later(index_height.next().into());
Expand All @@ -75,6 +74,7 @@ async fn catchup(
"indexing batch"
);
let last_height = events.last_height();
let mut dbtx = state_cp.begin_transaction().await?;
index.index_batch(&mut dbtx, events).await?;
tracing::debug!(index_name = &name, "committing batch");
IndexingState::update_index_height(&mut dbtx, &name, Height::from(last_height))
Expand Down

0 comments on commit 98fb73d

Please sign in to comment.