Use ExecuteDelete instead of ffetching data and then removing the entries

This commit is contained in:
2025-09-24 17:43:47 +02:00
parent 7954c4b72e
commit fc7b832926
8 changed files with 15 additions and 29 deletions

View File

@@ -15,9 +15,8 @@ public class RemoveOldNotificationsWorker(TimeSpan? interval = null, IEnumerable
protected override async Task<BaseWorker[]> DoWorkInternal()
{
Log.Debug("Removing old notifications...");
List<Notification> toRemove = await DbContext.Notifications.Where(n => n.IsSent).ToListAsync(CancellationToken);
Log.Debug($"Removing {toRemove.Count} old notifications...");
DbContext.RemoveRange(toRemove);
int removed = await DbContext.Notifications.Where(n => n.IsSent).ExecuteDeleteAsync(CancellationToken);
Log.Debug($"Removed {removed} old notifications...");
if(await DbContext.Sync(CancellationToken, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } e)
Log.Error($"Failed to save database changes: {e.exceptionMessage}");