From f94513a4ae74e52cb2d9ada869f664812e279c73 Mon Sep 17 00:00:00 2001 From: glax Date: Thu, 4 Sep 2025 22:15:29 +0200 Subject: [PATCH] Fix Manga ChangeLibrary Endpoint to be faster if library is the same. Fix MoveMangaLibraryWorker.cs setting off new Library --- API/Controllers/MangaController.cs | 5 ++++- API/Workers/MoveMangaLibraryWorker.cs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index 6cc8636..60f7443 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -443,10 +443,13 @@ public class MangaController(MangaContext context) : Controller [ProducesResponseType(Status404NotFound, "text/plain")] public async Task>> ChangeLibrary(string MangaId, string LibraryId) { - if (await context.MangaIncludeAll().FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga) + if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } manga) return TypedResults.NotFound(nameof(MangaId)); if (await context.FileLibraries.FirstOrDefaultAsync(l => l.Key == LibraryId, HttpContext.RequestAborted) is not { } library) return TypedResults.NotFound(nameof(LibraryId)); + + if(manga.LibraryId == library.Key) + return TypedResults.Ok(); MoveMangaLibraryWorker moveLibrary = new(manga, library); diff --git a/API/Workers/MoveMangaLibraryWorker.cs b/API/Workers/MoveMangaLibraryWorker.cs index 4c978f1..40d1cf0 100644 --- a/API/Workers/MoveMangaLibraryWorker.cs +++ b/API/Workers/MoveMangaLibraryWorker.cs @@ -33,7 +33,7 @@ public class MoveMangaLibraryWorker(Manga manga, FileLibrary toLibrary, IEnumera // Save old Path (to later move chapters) Dictionary oldPath = manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath); // Set new Path - DbContext.Entry(manga).Property(m => m.Library).CurrentValue = toLibrary; + manga.Library = toLibrary; if (await DbContext.Sync(CancellationToken) is { success: false }) return [];