perf(store-and-forward): bound retry sweep with SweepBatchLimit (default 500) on the due-rows query

This commit is contained in:
Joseph Doherty
2026-07-08 17:45:11 -04:00
parent e75cd6f3d8
commit 1a53b8082a
5 changed files with 47 additions and 2 deletions
@@ -180,7 +180,7 @@ public class StoreAndForwardStorage
/// Gets all messages that are due for retry (Pending status, last attempt older than retry interval).
/// </summary>
/// <returns>A task that resolves to the list of messages due for retry, ordered by creation time ascending.</returns>
public async Task<List<StoreAndForwardMessage>> GetMessagesForRetryAsync()
public async Task<List<StoreAndForwardMessage>> GetMessagesForRetryAsync(int limit = 0)
{
await using var connection = new SqliteConnection(_connectionString);
await connection.OpenAsync();
@@ -197,6 +197,13 @@ public class StoreAndForwardStorage
OR (julianday('now') - julianday(last_attempt_at)) * 86400000 >= retry_interval_ms)
ORDER BY created_at ASC";
// Bound the sweep batch (oldest-first). 0 = unlimited (legacy).
if (limit > 0)
{
cmd.CommandText += "\n LIMIT @limit";
cmd.Parameters.AddWithValue("@limit", limit);
}
cmd.Parameters.AddWithValue("@pending", (int)StoreAndForwardMessageStatus.Pending);
return await ReadMessagesAsync(cmd);