From e1e747d65badeefa7a55ff8e6f3163799f305c10 Mon Sep 17 00:00:00 2001 From: Oliver Kieselbach Date: Sun, 8 Feb 2026 12:55:16 +0100 Subject: [PATCH] more efficient delete via batching --- .../Services/TableStorageService.cs | 36 +++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Backend/AutopilotMonitor.Functions/Services/TableStorageService.cs b/src/Backend/AutopilotMonitor.Functions/Services/TableStorageService.cs index f6be8eeb..3cce4c64 100644 --- a/src/Backend/AutopilotMonitor.Functions/Services/TableStorageService.cs +++ b/src/Backend/AutopilotMonitor.Functions/Services/TableStorageService.cs @@ -595,10 +595,20 @@ namespace AutopilotMonitor.Functions.Services var events = tableClient.QueryAsync(filter); int deletedCount = 0; + var batch = new List(); await foreach (var eventEntity in events) { - await tableClient.DeleteEntityAsync(eventEntity.PartitionKey, eventEntity.RowKey); + batch.Add(new TableTransactionAction(TableTransactionActionType.Delete, eventEntity)); deletedCount++; + if (batch.Count >= 100) + { + await tableClient.SubmitTransactionAsync(batch); + batch.Clear(); + } + } + if (batch.Count > 0) + { + await tableClient.SubmitTransactionAsync(batch); } _logger.LogInformation($"Deleted {deletedCount} events for session {sessionId}"); @@ -1252,10 +1262,20 @@ namespace AutopilotMonitor.Functions.Services filter: $"PartitionKey eq '{tenantId}' and SessionId eq '{sessionId}'"); int deletedCount = 0; + var batch = new List(); await foreach (var entity in query) { - await tableClient.DeleteEntityAsync(entity.PartitionKey, entity.RowKey); + batch.Add(new TableTransactionAction(TableTransactionActionType.Delete, entity)); deletedCount++; + if (batch.Count >= 100) + { + await tableClient.SubmitTransactionAsync(batch); + batch.Clear(); + } + } + if (batch.Count > 0) + { + await tableClient.SubmitTransactionAsync(batch); } return deletedCount; @@ -1282,10 +1302,20 @@ namespace AutopilotMonitor.Functions.Services var query = tableClient.QueryAsync(filter: $"PartitionKey eq '{partitionKey}'"); int deletedCount = 0; + var batch = new List(); await foreach (var entity in query) { - await tableClient.DeleteEntityAsync(entity.PartitionKey, entity.RowKey); + batch.Add(new TableTransactionAction(TableTransactionActionType.Delete, entity)); deletedCount++; + if (batch.Count >= 100) + { + await tableClient.SubmitTransactionAsync(batch); + batch.Clear(); + } + } + if (batch.Count > 0) + { + await tableClient.SubmitTransactionAsync(batch); } return deletedCount;