mirror of
https://github.com/C9Glax/tranga.git
synced 2025-04-14 04:13:18 +02:00
Do not try and add duplicate chapters.
This commit is contained in:
parent
657ab571f9
commit
9b4baa1334
@ -24,13 +24,13 @@ public class RetrieveChaptersJob(ulong recurrenceMs, string mangaId, string? par
|
|||||||
Manga m = context.Manga.Find(MangaId)!;
|
Manga m = context.Manga.Find(MangaId)!;
|
||||||
MangaConnector connector = context.MangaConnectors.Find(m.MangaConnectorId)!;
|
MangaConnector connector = context.MangaConnectors.Find(m.MangaConnectorId)!;
|
||||||
// This gets all chapters that are not downloaded
|
// This gets all chapters that are not downloaded
|
||||||
Chapter[] allNewChapters = connector.GetNewChapters(m);
|
Chapter[] allNewChapters = connector.GetNewChapters(m).DistinctBy(c => c.ChapterId).ToArray();
|
||||||
|
|
||||||
// This filters out chapters that are not downloaded but already exist in the DB
|
// This filters out chapters that are not downloaded but already exist in the DB
|
||||||
string[] chapterIds = context.Chapters.Where(chapter => chapter.ParentMangaId == m.MangaId).Select(chapter => chapter.ChapterId).ToArray();
|
string[] chapterIds = context.Chapters.Where(chapter => chapter.ParentMangaId == m.MangaId).Select(chapter => chapter.ChapterId).ToArray();
|
||||||
Chapter[] newChapters = allNewChapters.Where(chapter => !chapterIds.Contains(chapter.ChapterId)).ToArray();
|
Chapter[] newChapters = allNewChapters.Where(chapter => !chapterIds.Contains(chapter.ChapterId)).ToArray();
|
||||||
context.Chapters.AddRangeAsync(newChapters).Wait();
|
context.Chapters.AddRange(newChapters);
|
||||||
context.SaveChangesAsync().Wait();
|
context.SaveChanges();
|
||||||
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user