From 5a2455a20ecf8a7437e24f873ba9269049ed7642 Mon Sep 17 00:00:00 2001 From: lisonge Date: Thu, 17 Oct 2024 22:13:16 +0800 Subject: [PATCH] perf: clear cache node --- .../li/songe/gkd/service/A11yContext.kt | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt b/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt index 9e4f669..57d632b 100644 --- a/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt +++ b/app/src/main/kotlin/li/songe/gkd/service/A11yContext.kt @@ -36,6 +36,12 @@ class A11yContext( var rootCache: AccessibilityNodeInfo? = null private fun clearNodeCache() { + if (META.debuggable) { + val sizeList = listOf(childCache.size(), parentCache.size(), indexCache.size()) + if (sizeList.any { it > 0 }) { + Log.d("cache", "clear cache -> $sizeList") + } + } rootCache = null try { childCache.evictAll() @@ -51,16 +57,17 @@ class A11yContext( } private var lastClearTime = 0L + private var lastAppChangeTime = appChangeTime private fun clearNodeCacheIfTimeout() { - val currentTime = System.currentTimeMillis() - if (currentTime - lastClearTime > 5000L) { - lastClearTime = currentTime - if (META.debuggable) { - val sizeList = listOf(childCache.size(), parentCache.size(), indexCache.size()) - if (sizeList.any { it > 0 }) { - Log.d("cache", "clear cache -> $sizeList") - } - } + if (appChangeTime != lastAppChangeTime) { + lastAppChangeTime = appChangeTime + lastClearTime = System.currentTimeMillis() + clearNodeCache() + return + } + val t = System.currentTimeMillis() + if (t - lastClearTime > 30_000L) { + lastClearTime = t clearNodeCache() } } @@ -74,10 +81,10 @@ class A11yContext( private fun guardInterrupt() { if (disableInterrupt) return if (interruptInnerKey == interruptKey) return - if (!activityRuleFlow.value.activePriority) return - val rule = currentRule ?: return - if (rule.isPriority()) return interruptInnerKey = interruptKey + val rule = currentRule ?: return + if (!activityRuleFlow.value.currentRules.contains(rule)) return + if (rule.isPriority()) return if (META.debuggable) { Log.d("guardInterrupt", "中断 rule=${rule.statusText()}") }