Skip to content

Commit

Permalink
cometindex: use faster event count logging
Browse files Browse the repository at this point in the history
COUNT(*) is actually relatively slow compared to taking the max rowid.
This is just for information, and spending ~1 second on this is not
worth it.
  • Loading branch information
cronokirby committed Sep 10, 2024
1 parent c2a75f5 commit fdfcfb1
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 @@ -141,7 +141,7 @@ impl Indexer {
let watermark = current_watermark.unwrap_or(0);

// Calculate new events count since the last watermark
sqlx::query_as::<_, (i64,)>("SELECT COUNT(*) FROM events WHERE rowid > $1")
sqlx::query_as::<_, (i64,)>("SELECT MAX(rowid) - $1 FROM events")
.bind(watermark)
.fetch_one(src_db)
.await
Expand Down

0 comments on commit fdfcfb1

Please sign in to comment.