Make cachePublications a dictionary with internalId as key.

This commit is contained in:
Glax 2024-04-22 22:38:23 +02:00
parent 79e61a62c7
commit daba940b45
10 changed files with 15 additions and 13 deletions

View File

@ -14,7 +14,7 @@ public abstract class GlobalBase
protected TrangaSettings settings { get; init; } protected TrangaSettings settings { get; init; }
protected HashSet<NotificationConnector> notificationConnectors { get; init; } protected HashSet<NotificationConnector> notificationConnectors { get; init; }
protected HashSet<LibraryConnector> libraryConnectors { get; init; } protected HashSet<LibraryConnector> libraryConnectors { get; init; }
protected List<Manga> cachedPublications { get; init; } protected Dictionary<string, Manga> cachedPublications { get; init; }
public static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." }; public static readonly NumberFormatInfo numberFormatDecimalPoint = new (){ NumberDecimalSeparator = "." };
protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.-]+(:[0-9]+)?"); protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.-]+(:[0-9]+)?");

View File

@ -160,10 +160,10 @@ public class JobBoss : GlobalBase
{ {
this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job); this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job);
if (job is DownloadNewChapters dncJob) if (job is DownloadNewChapters dncJob)
cachedPublications.Add(dncJob.manga); cachedPublications.Add(dncJob.manga.internalId, dncJob.manga);
} }
HashSet<string> coverFileNames = cachedPublications.Select(manga => manga.coverFileNameInCache!).ToHashSet(); HashSet<string> coverFileNames = cachedPublications.Select(manga => manga.Value.coverFileNameInCache!).ToHashSet();
foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers foreach (string fileName in Directory.GetFiles(settings.coverImageCache)) //Cleanup Unused Covers
{ {
if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga))) if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga)))

View File

@ -116,7 +116,7 @@ public class Bato : MangaConnector
Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary<string, string>(), Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary<string, string>(),
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
cachedPublications.Add(manga); cachedPublications.Add(manga.internalId, manga);
return manga; return manga;
} }

View File

@ -187,7 +187,7 @@ public class MangaDex : MangaConnector
status, status,
websiteUrl: $"https://mangadex.org/title/{publicationId}" websiteUrl: $"https://mangadex.org/title/{publicationId}"
); );
cachedPublications.Add(pub); cachedPublications.Add(pub.internalId, pub);
return pub; return pub;
} }

View File

@ -143,7 +143,7 @@ public class MangaKatana : MangaConnector
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
cachedPublications.Add(manga); cachedPublications.Add(manga.internalId, manga);
return manga; return manga;
} }

View File

@ -123,7 +123,7 @@ public class MangaLife : MangaConnector
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
cachedPublications.Add(manga); cachedPublications.Add(manga.internalId, manga);
return manga; return manga;
} }

View File

@ -133,7 +133,7 @@ public class Manganato : MangaConnector
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
cachedPublications.Add(manga); cachedPublications.Add(manga.internalId, manga);
return manga; return manga;
} }

View File

@ -179,7 +179,7 @@ public class Mangasee : MangaConnector
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
coverFileNameInCache, links, coverFileNameInCache, links,
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
cachedPublications.Add(manga); cachedPublications.Add(manga.internalId, manga);
return manga; return manga;
} }

View File

@ -120,7 +120,7 @@ public class Mangaworld: MangaConnector
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links, Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl); year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
cachedPublications.Add(manga); cachedPublications.Add(manga.internalId, manga);
return manga; return manga;
} }

View File

@ -56,9 +56,11 @@ public partial class Tranga : GlobalBase
public Manga? GetPublicationById(string internalId) public Manga? GetPublicationById(string internalId)
{ {
if (cachedPublications.Exists(publication => publication.internalId == internalId)) return cachedPublications.TryGetValue(internalId, out Manga manga) switch
return cachedPublications.First(publication => publication.internalId == internalId); {
return null; true => manga,
_ => null
};
} }
public bool TryGetPublicationById(string internalId, out Manga? manga) public bool TryGetPublicationById(string internalId, out Manga? manga)