perf: parse json

This commit is contained in:
lisonge 2024-08-08 21:10:08 +08:00
parent 3f21b49f43
commit 06956df916
2 changed files with 11 additions and 11 deletions

View File

@ -11,7 +11,6 @@ import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.http.ContentType
import io.ktor.serialization.kotlinx.json.json
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.json.Json
import li.songe.gkd.app
import okhttp3.OkHttpClient
@ -20,23 +19,24 @@ import java.time.Duration
import java.util.Locale
val kv by lazy { MMKV.mmkvWithID("kv")!! }
val kv by lazy { MMKV.mmkvWithID("kv") }
@OptIn(ExperimentalSerializationApi::class)
val json by lazy {
Json {
isLenient = true
ignoreUnknownKeys = true
explicitNulls = false
encodeDefaults = true
// support json5
isLenient = true // https://github.com/Kotlin/kotlinx.serialization/issues/2765
allowComments = true
allowTrailingComma = true
}
}
val keepNullJson by lazy {
Json {
isLenient = true
ignoreUnknownKeys = true
encodeDefaults = true
Json(from = json) {
explicitNulls = true
}
}

View File

@ -121,7 +121,7 @@ fun getGroupRawEnable(
enable
} else {
null
} ?: group.enable ?: true
} ?: group.enable != false
}
data class RuleSummary(
@ -190,7 +190,7 @@ val ruleSummaryFlow by lazy {
mutableMapOf<RawSubscription.RawGlobalGroup, List<GlobalRule>>()
rawSubs.globalGroups.filter { g ->
(subGlobalSubsConfigs.find { c -> c.groupKey == g.key }?.enable
?: g.enable ?: true) && g.valid
?: g.enable != false) && g.valid
}.forEach { groupRaw ->
val config = subGlobalSubsConfigs.find { c -> c.groupKey == groupRaw.key }
val g = ResolvedGlobalGroup(
@ -299,7 +299,7 @@ private fun loadSubs(id: Long): RawSubscription {
error("订阅文件不存在")
}
val subscription = try {
RawSubscription.parse(file.readText())
RawSubscription.parse(file.readText(), json5 = false)
} catch (e: Exception) {
throw Exception("订阅文件解析失败", e)
}