Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(capture-load-gen): delete the team in one statement (#102638)

Zach Browna8521791681b
diff --git a/rust/capture-load-gen/src/reset.rs b/rust/capture-load-gen/src/reset.rs
index 821084f7694f..fde4c3d8d935 100644
--- a/rust/capture-load-gen/src/reset.rs
+++ b/rust/capture-load-gen/src/reset.rs
@@ -5,10 +5,8 @@ use anyhow::{Context, Result};
use sqlx::postgres::PgPoolOptions;
use sqlx::{Executor, PgPool};
-/// So one chunk's delete fails fast on a lock instead of hanging the step.
-const STATEMENT_TIMEOUT_MS: u64 = 30_000;
-/// Rows deleted per statement.
-const RESET_CHUNK: i64 = 10_000;
+/// So a wedged delete fails the step instead of hanging it.
+const STATEMENT_TIMEOUT_MS: u64 = 300_000;
pub struct ResetConfig {
pub database_url: String,
@@ -35,7 +33,6 @@ pub async fn reset_team(cfg: &ResetConfig) -> Result<()> {
cfg.team_id,
&cfg.tmp_person_table,
&cfg.tmp_pdi_table,
- RESET_CHUNK,
)
.await
}
@@ -45,7 +42,6 @@ pub async fn reset_team_on_pool(
team_id: i64,
tmp_person_table: &str,
tmp_pdi_table: &str,
- chunk: i64,
) -> Result<()> {
// Distinct-id rows reference persons, so delete them first.
for table in [
@@ -54,24 +50,13 @@ pub async fn reset_team_on_pool(
"posthog_person",
tmp_person_table,
] {
- // Chunk the delete so millions of rows stay bounded and index-driven.
- let mut total = 0u64;
- loop {
- let deleted = sqlx::query(&format!(
- "DELETE FROM {table} WHERE team_id = $1 AND id IN \
- (SELECT id FROM {table} WHERE team_id = $1 LIMIT {chunk})"
- ))
+ let deleted = sqlx::query(&format!("DELETE FROM {table} WHERE team_id = $1"))
.bind(team_id)
.execute(pool)
.await
.with_context(|| format!("resetting {table}"))?
.rows_affected();
- total += deleted;
- if (deleted as i64) < chunk {
- break;
- }
- }
- tracing::info!(table, team_id, deleted = total, "reset team rows");
+ tracing::info!(table, team_id, deleted, "reset team rows");
}
Ok(())
}
diff --git a/rust/capture-load-gen/tests/parity.rs b/rust/capture-load-gen/tests/parity.rs
index 6d6011cbac33..a93fdf196dc5 100644
--- a/rust/capture-load-gen/tests/parity.rs
+++ b/rust/capture-load-gen/tests/parity.rs
@@ -210,7 +210,7 @@ async fn reset_clears_the_team_and_leaves_others(pool: PgPool) -> Result<()> {
insert_person(&pool, "posthog_person", 999, 1, true).await?;
insert_person(&pool, TMP_PERSON, 999, 1, true).await?;
- reset_team_on_pool(&pool, TEAM, TMP_PERSON, TMP_PDI, 2).await?;
+ reset_team_on_pool(&pool, TEAM, TMP_PERSON, TMP_PDI).await?;
for table in [
"posthog_person",