Make cachePublications a dictionary with internalId as key.
This commit is contained in:
parent
79e61a62c7
commit
daba940b45
@ -14,7 +14,7 @@ public abstract class GlobalBase
|
||||
protected TrangaSettings settings { get; init; }
|
||||
protected HashSet<NotificationConnector> notificationConnectors { 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 = "." };
|
||||
protected static readonly Regex baseUrlRex = new(@"https?:\/\/[0-9A-z\.-]+(:[0-9]+)?");
|
||||
|
||||
|
@ -160,10 +160,10 @@ public class JobBoss : GlobalBase
|
||||
{
|
||||
this.jobs.FirstOrDefault(jjob => jjob.id == job.parentJobId)?.AddSubJob(job);
|
||||
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
|
||||
{
|
||||
if(!coverFileNames.Any(existingManga => fileName.Contains(existingManga)))
|
||||
|
@ -116,7 +116,7 @@ public class Bato : MangaConnector
|
||||
|
||||
Manga manga = new (sortName, authors, description, altTitles, tags, posterUrl, coverFileNameInCache, new Dictionary<string, string>(),
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
cachedPublications.Add(manga.internalId, manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ public class MangaDex : MangaConnector
|
||||
status,
|
||||
websiteUrl: $"https://mangadex.org/title/{publicationId}"
|
||||
);
|
||||
cachedPublications.Add(pub);
|
||||
cachedPublications.Add(pub.internalId, pub);
|
||||
return pub;
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class MangaKatana : MangaConnector
|
||||
|
||||
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
cachedPublications.Add(manga.internalId, manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -123,7 +123,7 @@ public class MangaLife : MangaConnector
|
||||
|
||||
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
||||
coverFileNameInCache, links, year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
cachedPublications.Add(manga.internalId, manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class Manganato : MangaConnector
|
||||
|
||||
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
cachedPublications.Add(manga.internalId, manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -179,7 +179,7 @@ public class Mangasee : MangaConnector
|
||||
Manga manga = new(sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl,
|
||||
coverFileNameInCache, links,
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
cachedPublications.Add(manga.internalId, manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -120,7 +120,7 @@ public class Mangaworld: MangaConnector
|
||||
|
||||
Manga manga = new (sortName, authors.ToList(), description, altTitles, tags.ToArray(), posterUrl, coverFileNameInCache, links,
|
||||
year, originalLanguage, publicationId, releaseStatus, websiteUrl: websiteUrl);
|
||||
cachedPublications.Add(manga);
|
||||
cachedPublications.Add(manga.internalId, manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -56,9 +56,11 @@ public partial class Tranga : GlobalBase
|
||||
|
||||
public Manga? GetPublicationById(string internalId)
|
||||
{
|
||||
if (cachedPublications.Exists(publication => publication.internalId == internalId))
|
||||
return cachedPublications.First(publication => publication.internalId == internalId);
|
||||
return null;
|
||||
return cachedPublications.TryGetValue(internalId, out Manga manga) switch
|
||||
{
|
||||
true => manga,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
public bool TryGetPublicationById(string internalId, out Manga? manga)
|
||||
|
Loading…
Reference in New Issue
Block a user