mirror of
https://github.com/gkd-kit/gkd.git
synced 2024-11-16 11:42:22 +08:00
perf: parse json
This commit is contained in:
parent
3f21b49f43
commit
06956df916
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user