fix(usage): align cleanup loop break conditions with candidate row count

The cleanup loop break condition used rows_affected() from the UPDATE
statement, but for rows that only had blob/audit refs (no inline
compressed body data), the UPDATE reported 0 affected rows. This caused
the loop to exit after the first batch, skipping the majority of
candidates.

Change the break condition in all 4 cleanup functions from:
  if cleaned == 0 || cleaned < batch_size
to:
  if rows.len() < batch_size

This ensures the loop continues as long as SELECT returns a full batch,
regardless of how many rows the UPDATE actually modified.

Affected functions:
- cleanup_usage_raw_body_fields
- cleanup_usage_compressed_body_fields
- cleanup_usage_header_fields
- cleanup_usage_stale_body_fields
This commit is contained in:
Kayphoon
2026-06-16 04:19:58 +08:00
parent e2d5fc9dfb
commit 6d1b818414
@@ -683,7 +683,7 @@ async fn cleanup_usage_raw_body_fields(
.rows_affected();
let cleaned = usize::try_from(cleaned).unwrap_or(usize::MAX);
total_cleaned += cleaned;
if cleaned == 0 || cleaned < batch_size {
if rows.len() < batch_size {
break;
}
}
@@ -736,7 +736,7 @@ async fn cleanup_usage_compressed_body_fields(
.map_err(postgres_error)?;
let cleaned = usize::try_from(cleaned).unwrap_or(usize::MAX);
total_cleaned += cleaned;
if cleaned == 0 || cleaned < batch_size {
if rows.len() < batch_size {
break;
}
}
@@ -1143,7 +1143,7 @@ async fn cleanup_usage_header_fields(
.map_err(postgres_error)?;
let cleaned = usize::try_from(cleaned).unwrap_or(usize::MAX);
total_cleaned += cleaned;
if cleaned == 0 || cleaned < batch_size {
if rows.len() < batch_size {
break;
}
}
@@ -1213,7 +1213,7 @@ async fn cleanup_usage_stale_body_fields(
.map_err(postgres_error)?;
let cleaned = usize::try_from(cleaned).unwrap_or(usize::MAX);
total_cleaned += cleaned;
if cleaned == 0 || cleaned < batch_size {
if rows.len() < batch_size {
break;
}
}