mirror of
https://github.com/Suwayomi/Tachidesk.git
synced 2025-12-10 06:42:07 +01:00
Feature/web interface manager cache requests (#1773)
* Cache webui server mapping file * Cache webui preview version
This commit is contained in:
@@ -14,6 +14,7 @@ import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.awaitSuccess
|
||||
import io.github.oshai.kotlinlogging.KLogger
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import io.github.reactivecircus.cache4k.Cache
|
||||
import io.javalin.config.JavalinConfig
|
||||
import io.javalin.http.staticfiles.Location
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -65,6 +66,7 @@ import java.security.MessageDigest
|
||||
import java.util.Date
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.hours
|
||||
import kotlin.time.Duration.Companion.minutes
|
||||
import kotlin.time.Duration.Companion.seconds
|
||||
|
||||
private val applicationDirs: ApplicationDirs by injectLazy()
|
||||
@@ -91,6 +93,10 @@ object WebInterfaceManager {
|
||||
private val json: Json by injectLazy()
|
||||
private val network: NetworkHelper by injectLazy()
|
||||
|
||||
private val CACHE_DURATION = 5.minutes
|
||||
private val versionMappingCache = Cache.Builder<String, JsonArray>().expireAfterWrite(CACHE_DURATION).build()
|
||||
private val previewVersionCache = Cache.Builder<String, String>().expireAfterWrite(CACHE_DURATION).build()
|
||||
|
||||
private val notifyFlow = MutableSharedFlow<WebUIUpdateStatus?>()
|
||||
|
||||
private val statusFlow = MutableSharedFlow<WebUIUpdateStatus>()
|
||||
@@ -586,7 +592,10 @@ object WebInterfaceManager {
|
||||
}
|
||||
|
||||
private suspend fun fetchPreviewVersion(flavor: WebUIFlavor): String =
|
||||
executeWithRetry(KotlinLogging.logger("${logger.name} fetchPreviewVersion(${flavor.uiName})"), {
|
||||
previewVersionCache.get(flavor.uiName) {
|
||||
executeWithRetry(
|
||||
KotlinLogging.logger("${logger.name} fetchPreviewVersion(${flavor.uiName})"),
|
||||
{
|
||||
val releaseInfoJson =
|
||||
network.client
|
||||
.newCall(GET(flavor.latestReleaseInfoUrl))
|
||||
@@ -595,9 +604,12 @@ object WebInterfaceManager {
|
||||
.string()
|
||||
Json.decodeFromString<JsonObject>(releaseInfoJson)["tag_name"]?.jsonPrimitive?.content
|
||||
?: throw Exception("Failed to get the preview version tag")
|
||||
})
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun fetchServerMappingFile(flavor: WebUIFlavor): JsonArray =
|
||||
versionMappingCache.get(flavor.uiName) {
|
||||
executeWithRetry(
|
||||
KotlinLogging.logger("$logger fetchServerMappingFile(${flavor.uiName})"),
|
||||
{
|
||||
@@ -611,6 +623,7 @@ object WebInterfaceManager {
|
||||
).jsonArray
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
private suspend fun getLatestCompatibleVersion(flavor: WebUIFlavor): String {
|
||||
if (serverConfig.webUIChannel.value == WebUIChannel.BUNDLED) {
|
||||
|
||||
Reference in New Issue
Block a user