Skip to content

Commit 432194d

Browse files
committed
Small refactor
1 parent c297f3c commit 432194d

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

src/ServiceControl.Audit.Persistence.PostgreSQL/RetentionCleanupService.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ async Task CleanupOldMessagesAsync(CancellationToken cancellationToken)
5656

5757
async Task CleanupTable(string tableName, string dateColumn, DateTime cutoffDate, NpgsqlConnection conn, CancellationToken cancellationToken)
5858
{
59+
const int batchSize = 1000;
5960
var totalDeleted = 0;
6061

6162
while (!cancellationToken.IsCancellationRequested)
@@ -66,7 +67,7 @@ DELETE FROM {tableName}
6667
WHERE ctid IN (
6768
SELECT ctid FROM {tableName}
6869
WHERE {dateColumn} < @cutoff
69-
LIMIT 1000
70+
LIMIT {batchSize}
7071
);";
7172

7273
await using var cmd = new NpgsqlCommand(sql, conn);
@@ -75,7 +76,7 @@ LIMIT 1000
7576
var rows = await cmd.ExecuteNonQueryAsync(cancellationToken);
7677
totalDeleted += rows;
7778

78-
if (rows < 1000)
79+
if (rows < batchSize)
7980
{
8081
break; // no more rows to delete in this run
8182
}

0 commit comments

Comments
 (0)