From 4156365b183551dbef7dc71588c24503ea2f6986 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 4 Oct 2023 09:38:40 +0200 Subject: [PATCH] Improved logic on QueueContainsJob and AddJobTo Queue Added some documentation --- Tranga/Jobs/JobBoss.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Tranga/Jobs/JobBoss.cs b/Tranga/Jobs/JobBoss.cs index 06937da..7817584 100644 --- a/Tranga/Jobs/JobBoss.cs +++ b/Tranga/Jobs/JobBoss.cs @@ -37,6 +37,10 @@ public class JobBoss : GlobalBase AddJob(job); } + /// + /// Compares contents of the provided job and all current jobs + /// Does not check if objects are the same + /// public bool ContainsJobLike(Job job) { if (job is DownloadChapter dcJob) @@ -123,17 +127,16 @@ public class JobBoss : GlobalBase private bool QueueContainsJob(Job job) { - mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue()); + if (mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue()))//If we can add the queue, there is certainly no job in it + return true; return mangaConnectorJobQueue[job.mangaConnector].Contains(job); } public void AddJobToQueue(Job job) { Log($"Adding Job to Queue. {job}"); - mangaConnectorJobQueue.TryAdd(job.mangaConnector, new Queue()); - Queue connectorJobQueue = mangaConnectorJobQueue[job.mangaConnector]; - if(!connectorJobQueue.Contains(job)) - connectorJobQueue.Enqueue(job); + if(!QueueContainsJob(job)) + mangaConnectorJobQueue[job.mangaConnector].Enqueue(job); job.ExecutionEnqueue(); }