diff --git a/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt b/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt index ebc6d57e..1a7c9fe0 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/backend/BackendManager.kt @@ -43,6 +43,7 @@ class BackendManager( return mBackendProperties } val isOnRemovableDrive: Boolean get() = backendProperties?.isUsb == true + val requiresNetwork: Boolean get() = backendProperties?.requiresNetwork == true init { when (settingsManager.storagePluginType) { diff --git a/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt b/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt index 9943545e..7fda147a 100644 --- a/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt +++ b/app/src/main/java/com/stevesoltys/seedvault/repo/Checker.kt @@ -42,8 +42,8 @@ internal class Checker( private var snapshots: List? = null private val concurrencyLimit: Int get() { - // TODO determine also based on backendManager - return Runtime.getRuntime().availableProcessors() + val maxConcurrent = if (backendManager.requiresNetwork) 3 else 42 + return min(Runtime.getRuntime().availableProcessors(), maxConcurrent) } var checkerResult: CheckerResult? = null private set diff --git a/app/src/test/java/com/stevesoltys/seedvault/repo/CheckerTest.kt b/app/src/test/java/com/stevesoltys/seedvault/repo/CheckerTest.kt index 85dc3709..75241f40 100644 --- a/app/src/test/java/com/stevesoltys/seedvault/repo/CheckerTest.kt +++ b/app/src/test/java/com/stevesoltys/seedvault/repo/CheckerTest.kt @@ -86,6 +86,7 @@ internal class CheckerTest : TransportTest() { fun `check works even with no backup data`() = runBlocking { expectLoadingSnapshots(emptyMap()) + every { backendManager.requiresNetwork } returns Random.nextBoolean() every { nm.onCheckFinishedWithError(0, 0) } just Runs assertNull(checker.checkerResult) @@ -121,6 +122,7 @@ internal class CheckerTest : TransportTest() { snapshotHandle2 to snapshot.copy { token = 2 }, ) expectLoadingSnapshots(snapshotMap) + every { backendManager.requiresNetwork } returns Random.nextBoolean() val data = ByteArray(0) coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data) @@ -172,6 +174,7 @@ internal class CheckerTest : TransportTest() { }, ) expectLoadingSnapshots(snapshotMap) + every { backendManager.requiresNetwork } returns Random.nextBoolean() coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data1) coEvery { loader.loadFile(blobHandle2, null) } throws GeneralSecurityException() @@ -220,6 +223,7 @@ internal class CheckerTest : TransportTest() { val expectedSize = blob1.length.toLong() + blob2.length.toLong() expectLoadingSnapshots(snapshotMap) + every { backendManager.requiresNetwork } returns Random.nextBoolean() coEvery { loader.loadFile(blobHandle1, null) } returns ByteArrayInputStream(data1) coEvery { loader.loadFile(blobHandle2, null) } returns ByteArrayInputStream(data2) @@ -257,6 +261,7 @@ internal class CheckerTest : TransportTest() { }, ) expectLoadingSnapshots(snapshotMap) + every { backendManager.requiresNetwork } returns Random.nextBoolean() // only loading app data, not other blobs coEvery { loader.loadFile(appDataBlobHandle1, null) } throws SecurityException()