Optimize Download Queue (#1627)

* Optimize download Queue

* Lint

* Fix name of DownloadStatus file

* Re-add synchronous status fetch
This commit is contained in:
Mitchell Syer
2025-09-09 18:13:31 -04:00
committed by GitHub
parent 055c1c47f6
commit 679e2c0da9
10 changed files with 129 additions and 75 deletions

View File

@@ -17,7 +17,6 @@ import suwayomi.tachidesk.manga.impl.download.model.Status
import suwayomi.tachidesk.manga.model.table.ChapterTable
import suwayomi.tachidesk.server.JavalinSetup.Attribute
import suwayomi.tachidesk.server.JavalinSetup.future
import suwayomi.tachidesk.server.JavalinSetup.getAttribute
import suwayomi.tachidesk.server.user.requireUser
import java.util.concurrent.CompletableFuture
import kotlin.time.Duration.Companion.seconds
@@ -114,7 +113,7 @@ class DownloadMutation {
DownloadStatus(
DownloadManager.updates
.first {
DownloadManager.getStatus().queue.any { it.chapter.id in chapters }
DownloadManager.getStatus().queue.any { it.chapterId in chapters }
}.let { DownloadManager.getStatus() },
)
},
@@ -150,7 +149,7 @@ class DownloadMutation {
withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.updates
.first { it.updates.any { it.downloadChapter.chapter.id == chapter } }
.first { it.updates.any { it.downloadQueueItem.chapterId == chapter } }
.let { DownloadManager.getStatus() },
)
},
@@ -188,7 +187,7 @@ class DownloadMutation {
DownloadManager.updates
.first {
it.updates.any {
it.downloadChapter.chapter.id in chapters && it.type == DEQUEUED
it.downloadQueueItem.chapterId in chapters && it.type == DEQUEUED
}
}.let { DownloadManager.getStatus() },
)
@@ -227,7 +226,7 @@ class DownloadMutation {
DownloadManager.updates
.first {
it.updates.any {
it.downloadChapter.chapter.id == chapter && it.type == DEQUEUED
it.downloadQueueItem.chapterId == chapter && it.type == DEQUEUED
}
}.let { DownloadManager.getStatus() },
)
@@ -361,7 +360,7 @@ class DownloadMutation {
withTimeout(30.seconds) {
DownloadStatus(
DownloadManager.updates
.first { it.updates.indexOfFirst { it.downloadChapter.chapter.id == chapter } <= to }
.first { it.updates.indexOfFirst { it.downloadQueueItem.chapterId == chapter } <= to }
.let { DownloadManager.getStatus() },
)
},

View File

@@ -17,7 +17,7 @@ import suwayomi.tachidesk.graphql.server.primitives.Node
import suwayomi.tachidesk.graphql.server.primitives.NodeList
import suwayomi.tachidesk.graphql.server.primitives.PageInfo
import suwayomi.tachidesk.graphql.types.DownloadState.FINISHED
import suwayomi.tachidesk.manga.impl.download.model.DownloadChapter
import suwayomi.tachidesk.manga.impl.download.model.DownloadQueueItem
import suwayomi.tachidesk.manga.impl.download.model.DownloadStatus
import suwayomi.tachidesk.manga.impl.download.model.DownloadUpdate
import suwayomi.tachidesk.manga.impl.download.model.DownloadUpdateType
@@ -71,8 +71,8 @@ class DownloadType(
val tries: Int,
val position: Int,
) : Node {
constructor(downloadChapter: DownloadChapter) : this(
downloadChapter.chapter.id,
constructor(downloadChapter: DownloadQueueItem) : this(
downloadChapter.chapterId,
downloadChapter.mangaId,
when (downloadChapter.state) {
OtherDownloadState.Queued -> DownloadState.QUEUED
@@ -110,7 +110,7 @@ class DownloadUpdate(
) : Node {
constructor(downloadUpdate: DownloadUpdate) : this(
downloadUpdate.type,
DownloadType(downloadUpdate.downloadChapter),
DownloadType(downloadUpdate.downloadQueueItem),
)
}