diff --git a/API/Controllers/FileLibraryController.cs b/API/Controllers/FileLibraryController.cs index 1fa2db7..91a9056 100644 --- a/API/Controllers/FileLibraryController.cs +++ b/API/Controllers/FileLibraryController.cs @@ -135,11 +135,9 @@ public class FileLibraryController(MangaContext context) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task, InternalServerError>> DeleteLocalLibrary (string FileLibraryId) { - if(await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == FileLibraryId, HttpContext.RequestAborted) is not { } library) + if(await context.FileLibraries.Where(l => l.Key == FileLibraryId).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1) return TypedResults.NotFound(nameof(FileLibraryId)); - context.FileLibraries.Remove(library); - if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result) return TypedResults.InternalServerError(result.exceptionMessage); return TypedResults.Ok(); diff --git a/API/Controllers/LibraryConnectorController.cs b/API/Controllers/LibraryConnectorController.cs index 5b02186..92e96fa 100644 --- a/API/Controllers/LibraryConnectorController.cs +++ b/API/Controllers/LibraryConnectorController.cs @@ -90,11 +90,9 @@ public class LibraryConnectorController(LibraryContext context) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task, InternalServerError>> DeleteConnector (string LibraryConnectorId) { - if (await context.LibraryConnectors.FirstOrDefaultAsync(l => l.Key == LibraryConnectorId) is not { } connector) + if (await context.LibraryConnectors.Where(l => l.Key == LibraryConnectorId).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1) return TypedResults.NotFound(nameof(LibraryConnectorId)); - context.LibraryConnectors.Remove(connector); - if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result) return TypedResults.InternalServerError(result.exceptionMessage); return TypedResults.Ok(); diff --git a/API/Controllers/MaintenanceController.cs b/API/Controllers/MaintenanceController.cs index 34ae9bb..c2f588e 100644 --- a/API/Controllers/MaintenanceController.cs +++ b/API/Controllers/MaintenanceController.cs @@ -24,13 +24,10 @@ public class MaintenanceController(MangaContext mangaContext) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task>> CleanupNoDownloadManga() { - if (await mangaContext.Mangas - .Include(m => m.MangaConnectorIds) - .Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload)) - .ToArrayAsync(HttpContext.RequestAborted) is not { } noDownloads) - return TypedResults.InternalServerError("Could not fetch Manga"); - - mangaContext.Mangas.RemoveRange(noDownloads); + await mangaContext.Mangas + .Include(m => m.MangaConnectorIds) + .Where(m => !m.MangaConnectorIds.Any(id => id.UseForDownload)) + .ExecuteDeleteAsync(HttpContext.RequestAborted); if(await mangaContext.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result) return TypedResults.InternalServerError(result.exceptionMessage); diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index 509f5c8..3992fe0 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -149,11 +149,9 @@ public class MangaController(MangaContext context) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task, InternalServerError>> DeleteManga (string MangaId) { - if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga) + if(await context.Mangas.Where(m => m.Key == MangaId).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1) return TypedResults.NotFound(nameof(MangaId)); - context.Mangas.Remove(manga); - if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result) return TypedResults.InternalServerError(result.exceptionMessage); return TypedResults.Ok(); diff --git a/API/Controllers/MetadataFetcherController.cs b/API/Controllers/MetadataFetcherController.cs index 79755bc..353b402 100644 --- a/API/Controllers/MetadataFetcherController.cs +++ b/API/Controllers/MetadataFetcherController.cs @@ -112,15 +112,13 @@ public class MetadataFetcherController(MangaContext context) : Controller [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task, InternalServerError, StatusCodeHttpResult>> UnlinkMangaMetadata (string MangaId, string MetadataFetcherName) { - if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } _) + if (! await context.Mangas.AnyAsync(m => m.Key == MangaId, HttpContext.RequestAborted)) return TypedResults.NotFound(nameof(MangaId)); - if(Tranga.MetadataFetchers.FirstOrDefault(f => f.Name == MetadataFetcherName) is null) + if(Tranga.MetadataFetchers.All(f => f.Name != MetadataFetcherName)) return TypedResults.BadRequest(); - if (context.MetadataEntries.FirstOrDefault(e => - e.MangaId == MangaId && e.MetadataFetcherName == MetadataFetcherName) is not { } entry) + if (await context.MetadataEntries.Where(e => e.MangaId == MangaId && e.MetadataFetcherName == MetadataFetcherName) + .ExecuteDeleteAsync(HttpContext.RequestAborted) < 1) return TypedResults.StatusCode(Status412PreconditionFailed); - - context.Remove(entry); if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result) return TypedResults.InternalServerError(result.exceptionMessage); diff --git a/API/Controllers/NotificationConnectorController.cs b/API/Controllers/NotificationConnectorController.cs index ca5f079..63910f6 100644 --- a/API/Controllers/NotificationConnectorController.cs +++ b/API/Controllers/NotificationConnectorController.cs @@ -163,11 +163,9 @@ public class NotificationConnectorController(NotificationsContext context) : Con [ProducesResponseType(Status500InternalServerError, "text/plain")] public async Task, InternalServerError>> DeleteConnector (string Name) { - if (await context.NotificationConnectors.FirstOrDefaultAsync(c => c.Name == Name, HttpContext.RequestAborted) is not { } connector) + if (await context.NotificationConnectors.Where(c => c.Name == Name).ExecuteDeleteAsync(HttpContext.RequestAborted) < 1) return TypedResults.NotFound(nameof(Name)); - context.NotificationConnectors.Remove(connector); - if(await context.Sync(HttpContext.RequestAborted, GetType(), System.Reflection.MethodBase.GetCurrentMethod()?.Name) is { success: false } result) return TypedResults.InternalServerError(result.exceptionMessage); return TypedResults.Ok(); diff --git a/API/Program.cs b/API/Program.cs index a53b5ac..edeb6de 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -132,7 +132,7 @@ using (IServiceScope scope = app.Services.CreateScope()) await context.Database.MigrateAsync(CancellationToken.None); await context.Database.EnsureCreatedAsync(CancellationToken.None); - context.Notifications.RemoveRange(context.Notifications); + context.Notifications.ExecuteDelete(); string[] emojis = ["(•‿•)", "(づ \u25d5‿\u25d5 )づ", "( \u02d8\u25bd\u02d8)っ\u2668", "=\uff3e\u25cf \u22cf \u25cf\uff3e=", "(ΦωΦ)", "(\u272a\u3268\u272a)", "( ノ・o・ )ノ", "(〜^\u2207^ )〜", "~(\u2267ω\u2266)~","૮ \u00b4• ﻌ \u00b4• ა", "(\u02c3ᆺ\u02c2)", "(=\ud83d\udf66 \u0f1d \ud83d\udf66=)" ]; await context.Notifications.AddAsync(new ("Tranga Started", emojis[Random.Shared.Next(0, emojis.Length - 1)], NotificationUrgency.High), CancellationToken.None); diff --git a/API/Workers/PeriodicWorkers/MaintenanceWorkers/RemoveOldNotificationsWorker.cs b/API/Workers/PeriodicWorkers/MaintenanceWorkers/RemoveOldNotificationsWorker.cs index d1e69ce..6d20bee 100644 --- a/API/Workers/PeriodicWorkers/MaintenanceWorkers/RemoveOldNotificationsWorker.cs +++ b/API/Workers/PeriodicWorkers/MaintenanceWorkers/RemoveOldNotificationsWorker.cs @@ -15,9 +15,8 @@ public class RemoveOldNotificationsWorker(TimeSpan? interval = null, IEnumerable protected override async Task DoWorkInternal() { Log.Debug("Removing old notifications..."); - List 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}");