From d46bbdc219915cf1a90f359b173980103f08562d Mon Sep 17 00:00:00 2001 From: 2dust <31833384+2dust@users.noreply.github.com> Date: Thu, 29 Jan 2026 14:34:15 +0800 Subject: [PATCH] Refactor duplicate server removal logic --- .../com/v2ray/ang/viewmodel/MainViewModel.kt | 20 +++++++------------ 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt index 7ab771ef..0b0de831 100644 --- a/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt +++ b/V2rayNG/app/src/main/java/com/v2ray/ang/viewmodel/MainViewModel.kt @@ -15,7 +15,6 @@ import com.v2ray.ang.AngApplication import com.v2ray.ang.AppConfig import com.v2ray.ang.R import com.v2ray.ang.dto.GroupMapItem -import com.v2ray.ang.dto.ProfileItem import com.v2ray.ang.dto.ServersCache import com.v2ray.ang.dto.SubscriptionCache import com.v2ray.ang.extension.serializable @@ -310,20 +309,15 @@ class MainViewModel(application: Application) : AndroidViewModel(application) { * @return The number of removed servers. */ fun removeDuplicateServer(): Int { - val serversCacheCopy = mutableListOf>() - for (it in serversCache) { - val config = MmkvManager.decodeServerConfig(it.guid) ?: continue - serversCacheCopy.add(Pair(it.guid, config)) - } - + val serversCacheCopy = serversCache.toList().toMutableList() val deleteServer = mutableListOf() - serversCacheCopy.forEachIndexed { index, it -> - val outbound = it.second - serversCacheCopy.forEachIndexed { index2, it2 -> + serversCacheCopy.forEachIndexed { index, sc -> + val profile = sc.profile + serversCacheCopy.forEachIndexed { index2, sc2 -> if (index2 > index) { - val outbound2 = it2.second - if (outbound.equals(outbound2) && !deleteServer.contains(it2.first)) { - deleteServer.add(it2.first) + val profile2 = sc2.profile + if (profile == profile2 && !deleteServer.contains(sc2.guid)) { + deleteServer.add(sc2.guid) } } }