perf(prefs): разбор серверов только при их изменении

This commit is contained in:
samosvalishe committed 2026-09-22 20:11:36 +03:00
1 parent bba32ea051
commit 017876d62e
1 file changed
+6 -3
@@ -90,10 +90,13 @@ class AppPreferences(context: Context) {
.catch { if (it is IOException) emit(emptyPreferences()) else throw it } .catch { if (it is IOException) emit(emptyPreferences()) else throw it }
.map(transform) .map(transform)
val serversSnapshot: Flow<ServersSnapshot> = prefFlow { prefs -> val serversSnapshot: Flow<ServersSnapshot> =
prefFlow { prefs -> prefs[SERVERS_JSON] to prefs[ACTIVE_SERVER_ID] }
.distinctUntilChanged()
.map { (json, activeId) ->
ServersSnapshot( ServersSnapshot(
list = ServerJson.decodeList(prefs[SERVERS_JSON]), list = ServerJson.decodeList(json),
activeId = prefs[ACTIVE_SERVER_ID]?.takeIf { it.isNotBlank() }, activeId = activeId?.takeIf { it.isNotBlank() },
loaded = true loaded = true
) )
} }