Make cachedPublications private with getter-setter
This commit is contained in:
parent
daba940b45
commit
762da4c859
@ -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 Dictionary<string, Manga> cachedPublications { get; init; }
|
||||
private 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]+)?");
|
||||
|
||||
@ -36,6 +36,29 @@ public abstract class GlobalBase
|
||||
this.cachedPublications = new();
|
||||
}
|
||||
|
||||
protected void AddMangaToCache(Manga manga)
|
||||
{
|
||||
if (!this.cachedPublications.TryAdd(manga.internalId, manga))
|
||||
{
|
||||
Log($"Overwriting Manga {manga.internalId}");
|
||||
this.cachedPublications[manga.internalId] = manga;
|
||||
}
|
||||
}
|
||||
|
||||
protected Manga? GetCachedManga(string internalId)
|
||||
{
|
||||
return cachedPublications.TryGetValue(internalId, out Manga manga) switch
|
||||
{
|
||||
true => manga,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
|
||||
protected IEnumerable<Manga> GetAllCachedManga()
|
||||
{
|
||||
return cachedPublications.Values;
|
||||
}
|
||||
|
||||
protected void Log(string message)
|
||||
{
|
||||
logger?.WriteLine(this.GetType().Name, message);
|
||||
|
@ -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.internalId, dncJob.manga);
|
||||
AddMangaToCache(dncJob.manga);
|
||||
}
|
||||
|
||||
HashSet<string> coverFileNames = cachedPublications.Select(manga => manga.Value.coverFileNameInCache!).ToHashSet();
|
||||
HashSet<string> coverFileNames = GetAllCachedManga().Select(manga => manga.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.internalId, manga);
|
||||
AddMangaToCache(manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -187,7 +187,7 @@ public class MangaDex : MangaConnector
|
||||
status,
|
||||
websiteUrl: $"https://mangadex.org/title/{publicationId}"
|
||||
);
|
||||
cachedPublications.Add(pub.internalId, pub);
|
||||
AddMangaToCache(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.internalId, manga);
|
||||
AddMangaToCache(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.internalId, manga);
|
||||
AddMangaToCache(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.internalId, manga);
|
||||
AddMangaToCache(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.internalId, manga);
|
||||
AddMangaToCache(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.internalId, manga);
|
||||
AddMangaToCache(manga);
|
||||
return manga;
|
||||
}
|
||||
|
||||
|
@ -54,14 +54,7 @@ public partial class Tranga : GlobalBase
|
||||
return _connectors;
|
||||
}
|
||||
|
||||
public Manga? GetPublicationById(string internalId)
|
||||
{
|
||||
return cachedPublications.TryGetValue(internalId, out Manga manga) switch
|
||||
{
|
||||
true => manga,
|
||||
_ => null
|
||||
};
|
||||
}
|
||||
public Manga? GetPublicationById(string internalId) => GetCachedManga(internalId);
|
||||
|
||||
public bool TryGetPublicationById(string internalId, out Manga? manga)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user