mirror of
https://github.com/C9Glax/tranga.git
synced 2025-02-23 07:40:13 +01:00
[postgres-Server-V2] fix: pk conflict error in chapter download (still not working though)
This commit is contained in:
parent
ef7ebf022d
commit
6315940cd6
@ -12,11 +12,22 @@ public class DownloadNewChaptersJob(ulong recurrenceMs, string mangaId, string?
|
|||||||
|
|
||||||
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
|
||||||
{
|
{
|
||||||
Manga m = Manga ?? context.Manga.Find(MangaId)!;
|
/*
|
||||||
MangaConnector connector = m.MangaConnector ?? context.MangaConnectors.Find(m.MangaConnectorId)!;
|
* For some reason, directly using Manga from above instead of finding it again causes DBContext to consider
|
||||||
Chapter[] newChapters = connector.GetNewChapters(m);
|
* Manga as a new entity and Postgres throws a Duplicate PK exception.
|
||||||
|
* m.MangaConnector does not have this issue (IDK why).
|
||||||
|
*/
|
||||||
|
Manga m = context.Manga.Find(MangaId)!;
|
||||||
|
MangaConnector connector = context.MangaConnectors.Find(m.MangaConnectorId)!;
|
||||||
|
// This gets all chapters that are not downloaded
|
||||||
|
Chapter[] allNewChapters = connector.GetNewChapters(m);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
Chapter[] newChapters = allNewChapters.Where(chapter => !chapterIds.Contains(chapter.ChapterId)).ToArray();
|
||||||
context.Chapters.AddRangeAsync(newChapters).Wait();
|
context.Chapters.AddRangeAsync(newChapters).Wait();
|
||||||
context.SaveChangesAsync().Wait();
|
context.SaveChangesAsync().Wait();
|
||||||
return newChapters.Select(chapter => new DownloadSingleChapterJob(chapter.ChapterId, this.JobId));
|
|
||||||
|
return allNewChapters.Select(chapter => new DownloadSingleChapterJob(chapter.ChapterId, this.JobId));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user