From 1e53a9b38970339965f5da0515ea5dc4cf1278d2 Mon Sep 17 00:00:00 2001 From: FooIbar <118464521+FooIbar@users.noreply.github.com> Date: Sat, 18 May 2024 00:30:54 +0800 Subject: [PATCH] Make sure favorites don't have the same timestamp --- .../main/kotlin/com/hippo/ehviewer/client/EhEngine.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt index f84b052f8..ccee8954c 100644 --- a/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt +++ b/app/src/main/kotlin/com/hippo/ehviewer/client/EhEngine.kt @@ -65,6 +65,7 @@ import io.ktor.utils.io.pool.useInstance import java.io.File import java.nio.ByteBuffer import kotlin.math.ceil +import kotlin.system.measureTimeMillis import kotlinx.coroutines.CancellationException import kotlinx.coroutines.delay import kotlinx.serialization.SerializationException @@ -452,13 +453,13 @@ object EhEngine { } suspend fun addFavorites(galleryList: List>, dstCat: Int) { - galleryList.chunked(MAX_SEQUENTIAL_REQUESTS).forEachIndexed { index, chunk -> - if (index != 0) { - delay(REQUEST_INTERVAL) - } - chunk.parMap { (gid, token) -> + galleryList.forEach { (gid, token) -> + // https://github.com/FooIbar/EhViewer/issues/1190 + // Workaround for duplicate items when sorting by favorited time + val timeTaken = measureTimeMillis { modifyFavorites(gid, token, dstCat) } + delay(1000 - timeTaken) } } }