下载代码优化

This commit is contained in:
HapeLee committed 2026-05-13 21:54:19 +08:00
1 parent 876f1370ec
commit b90b9f034d
3 files changed
+25 -3

No files matched your search

+2 -1
View File
@@ -67,7 +67,8 @@
"Bash(Test-Path *)", "Bash(Test-Path *)",
"Bash(git stash *)", "Bash(git stash *)",
"Bash(Select-String -Pattern \"FAILED|error:\")", "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() 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) { fun setWorkingState(value: Boolean) {
coordinator.setWorkingState(value) coordinator.setWorkingState(value)
} }
@@ -52,6 +52,7 @@ class CacheBookService : BaseService() {
private const val DIAGNOSTICS_LOG_INTERVAL_MILLIS = 5_000L private const val DIAGNOSTICS_LOG_INTERVAL_MILLIS = 5_000L
private const val MAX_IDLE_SPIN_MS = 60_000L private const val MAX_IDLE_SPIN_MS = 60_000L
@Volatile
var isRun = false var isRun = false
private set private set
} }
@@ -183,9 +184,9 @@ class CacheBookService : BaseService() {
admissionIdleWaiters.values.flatten().forEach { it.complete(Unit) } admissionIdleWaiters.values.flatten().forEach { it.complete(Unit) }
admissionIdleWaiters.clear() admissionIdleWaiters.clear()
} }
CacheBook.close(clearFailureState = false) CacheBook.shutdownPreservingPaused()
serviceCommandScope.cancel()
super.onDestroy() super.onDestroy()
serviceCommandScope.cancel()
} }
private fun reconstructRequestFromIntent(intent: Intent): CacheDownloadRequest? { private fun reconstructRequestFromIntent(intent: Intent): CacheDownloadRequest? {