Jobs remove redundant fields (context tracking)
Some checks failed
Docker Image CI / build (push) Has been cancelled

This commit is contained in:
2025-04-02 02:16:55 +02:00
parent f085c5cf8e
commit a490e233d7
10 changed files with 906 additions and 103 deletions

View File

@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace API.Schema.Jobs;
@ -10,9 +9,6 @@ public class DownloadAvailableChaptersJob(ulong recurrenceMs, string mangaId, st
[Required]
public string MangaId { get; init; } = mangaId;
[JsonIgnore]
public Manga? Manga { get; init; }
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
return context.Chapters.Where(c => c.ParentMangaId == MangaId).AsEnumerable()

View File

@ -1,5 +1,4 @@
using System.ComponentModel.DataAnnotations;
using Newtonsoft.Json;
namespace API.Schema.Jobs;
@ -9,12 +8,10 @@ public class DownloadMangaCoverJob(string mangaId, string? parentJobId = null, I
[StringLength(64)]
[Required]
public string MangaId { get; init; } = mangaId;
[JsonIgnore]
public Manga? Manga { get; init; }
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
Manga? manga = Manga ?? context.Mangas.Find(this.MangaId);
Manga? manga = context.Mangas.Find(this.MangaId);
if (manga is null)
{
Log.Error($"Manga {this.MangaId} not found.");

View File

@ -3,7 +3,6 @@ using System.IO.Compression;
using System.Runtime.InteropServices;
using API.MangaDownloadClients;
using API.Schema.MangaConnectors;
using Newtonsoft.Json;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Formats.Jpeg;
using SixLabors.ImageSharp.Processing;
@ -19,24 +18,21 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
[Required]
public string ChapterId { get; init; } = chapterId;
[JsonIgnore]
public Chapter? Chapter { get; init; }
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
Chapter? chapter = Chapter ?? context.Chapters.Find(ChapterId);
Chapter? chapter = context.Chapters.Find(ChapterId);
if (chapter is null)
{
Log.Error("Chapter is null.");
return [];
}
Manga? manga = chapter.ParentManga ?? context.Mangas.Find(chapter.ParentMangaId);
Manga? manga = context.Mangas.Find(chapter.ParentMangaId) ?? chapter.ParentManga;
if (manga is null)
{
Log.Error("Manga is null.");
return [];
}
MangaConnector? connector = manga.MangaConnector ?? context.MangaConnectors.Find(manga.MangaConnectorId);
MangaConnector? connector = context.MangaConnectors.Find(manga.MangaConnectorId) ?? manga.MangaConnector;
if (connector is null)
{
Log.Error("Connector is null.");
@ -45,7 +41,7 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu
string[] imageUrls = connector.GetChapterImageUrls(chapter);
if (imageUrls.Length < 1)
{
Log.Info($"No imageUrls for chapter {chapterId}");
Log.Info($"No imageUrls for chapter {ChapterId}");
return [];
}
string? saveArchiveFilePath = chapter.FullArchiveFilePath;

View File

@ -1,7 +1,6 @@
using System.ComponentModel.DataAnnotations;
using API.Schema.MangaConnectors;
using Microsoft.EntityFrameworkCore;
using Newtonsoft.Json;
namespace API.Schema.Jobs;
@ -12,12 +11,9 @@ public class RetrieveChaptersJob(ulong recurrenceMs, string mangaId, string? par
[Required]
public string MangaId { get; init; } = mangaId;
[JsonIgnore]
public Manga? Manga { get; init; }
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
Manga? manga = context.Mangas.Find(MangaId) ?? Manga;
Manga? manga = context.Mangas.Find(MangaId);
if (manga is null)
{
Log.Error("Manga is null.");

View File

@ -10,9 +10,6 @@ public class UpdateFilesDownloadedJob(ulong recurrenceMs, string mangaId, string
[Required]
public string MangaId { get; init; } = mangaId;
[JsonIgnore]
public virtual Manga? Manga { get; init; }
protected override IEnumerable<Job> RunInternal(PgsqlContext context)
{
IQueryable<Chapter> chapters = context.Chapters.Where(c => c.ParentMangaId == MangaId);