Load entry references and collections

This commit is contained in:
Glax 2025-05-18 13:53:23 +02:00
parent 698d138642
commit 4e7a725fee
5 changed files with 9 additions and 1 deletions

View File

@ -36,6 +36,7 @@ public class DownloadAvailableChaptersJob : Job
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
context.Entry(Manga).Reference<LocalLibrary>(m => m.Library).Load();
return Manga.Chapters.Where(c => c.Downloaded == false).Select(chapter => new DownloadSingleChapterJob(chapter, this));
}
}

View File

@ -42,6 +42,8 @@ public class MoveMangaLibraryJob : Job
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
context.Entry(Manga).Collection<Chapter>(m => m.Chapters).Load();
context.Entry(Manga).Reference<LocalLibrary>(m => m.Library).Load();
Dictionary<Chapter, string> oldPath = Manga.Chapters.ToDictionary(c => c, c => c.FullArchiveFilePath);
Manga.Library = ToLibrary;
try

View File

@ -40,6 +40,7 @@ public class RetrieveChaptersJob : Job
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
context.Entry(Manga).Collection<Chapter>(m => m.Chapters).Load();
// This gets all chapters that are not downloaded
Chapter[] allChapters = Manga.MangaConnector.GetChapters(Manga, Language).DistinctBy(c => c.ChapterId).ToArray();
Chapter[] newChapters = allChapters.Where(chapter => Manga.Chapters.Contains(chapter) == false).ToArray();
@ -47,7 +48,8 @@ public class RetrieveChaptersJob : Job
try
{
context.Chapters.AddRange(newChapters);
foreach (Chapter newChapter in newChapters)
Manga.Chapters.Add(newChapter);
context.SaveChanges();
}
catch (DbUpdateException e)

View File

@ -36,6 +36,7 @@ public class UpdateChaptersDownloadedJob : Job
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
context.Entry(Manga).Collection<Chapter>(m => m.Chapters).Load();
return Manga.Chapters.Select(c => new UpdateSingleChapterDownloadedJob(c, this));
}
}

View File

@ -37,6 +37,8 @@ public class UpdateSingleChapterDownloadedJob : Job
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
context.Entry(Chapter).Reference<Manga>(c => c.ParentManga).Load();
context.Entry(Chapter.ParentManga).Reference<LocalLibrary>(m => m.Library).Load();
Chapter.Downloaded = Chapter.CheckDownloaded();
try