下载代码优化

This commit is contained in:
HapeLee
2026-05-13 21:54:19 +08:00
parent 876f1370ec
commit b90b9f034d
3 changed files with 25 additions and 3 deletions
+2 -1
View File
@@ -67,7 +67,8 @@
"Bash(Test-Path *)",
"Bash(git stash *)",
"Bash(Select-String -Pattern \"FAILED|error:\")",
"Bash(Select-Object -First 5)"
"Bash(Select-Object -First 5)",
"Bash(Select-String -NotMatch \"^\\\\s*$\")"
]
}
}
@@ -474,6 +474,26 @@ object CacheBook {
updateSummary()
}
fun shutdownPreservingPaused() {
isPaused = false
val toRemove = ArrayList<String>()
cacheBookMap.forEach { (bookUrl, model) ->
val keep = synchronized(model) {
model.isPaused() || model.pausedIndices().isNotEmpty()
}
if (keep) return@forEach
toRemove.add(bookUrl)
model.stop()
}
toRemove.forEach { cacheBookMap.remove(it) }
successDownloadCount.set(0)
pendingRemoveRequests.values.forEach { it.complete(false) }
pendingRemoveRequests.clear()
clearPendingAdmissions()
stateStore.clearRuntimeState()
updateSummary()
}
fun setWorkingState(value: Boolean) {
coordinator.setWorkingState(value)
}
@@ -52,6 +52,7 @@ class CacheBookService : BaseService() {
private const val DIAGNOSTICS_LOG_INTERVAL_MILLIS = 5_000L
private const val MAX_IDLE_SPIN_MS = 60_000L
@Volatile
var isRun = false
private set
}
@@ -183,9 +184,9 @@ class CacheBookService : BaseService() {
admissionIdleWaiters.values.flatten().forEach { it.complete(Unit) }
admissionIdleWaiters.clear()
}
CacheBook.close(clearFailureState = false)
serviceCommandScope.cancel()
CacheBook.shutdownPreservingPaused()
super.onDestroy()
serviceCommandScope.cancel()
}
private fun reconstructRequestFromIntent(intent: Intent): CacheDownloadRequest? {