feat: Optimize coroutine usage in ChatViewModel for improved performance and responsiveness & FIX LAGS
This commit is contained in:
@@ -24,7 +24,8 @@ object ProtocolManager {
|
||||
private var messageRepository: MessageRepository? = null
|
||||
private val scope = CoroutineScope(Dispatchers.IO + SupervisorJob())
|
||||
|
||||
// Debug logs for dev console
|
||||
// Debug logs for dev console - 🚀 ОТКЛЮЧЕНО для производительности
|
||||
// Логи только в Logcat, не в StateFlow (это вызывало ANR!)
|
||||
private val _debugLogs = MutableStateFlow<List<String>>(emptyList())
|
||||
val debugLogs: StateFlow<List<String>> = _debugLogs.asStateFlow()
|
||||
|
||||
@@ -34,11 +35,23 @@ object ProtocolManager {
|
||||
|
||||
private val dateFormat = SimpleDateFormat("HH:mm:ss.SSS", Locale.getDefault())
|
||||
|
||||
// 🚀 Флаг для включения UI логов (по умолчанию ВЫКЛЮЧЕНО - это вызывало ANR!)
|
||||
private var uiLogsEnabled = false
|
||||
|
||||
fun addLog(message: String) {
|
||||
val timestamp = dateFormat.format(Date())
|
||||
val logLine = "[$timestamp] $message"
|
||||
// Только Logcat - быстро и не блокирует UI
|
||||
Log.d(TAG, logLine)
|
||||
_debugLogs.value = (_debugLogs.value + logLine).takeLast(100)
|
||||
|
||||
// UI логи отключены по умолчанию - вызывали ANR из-за перекомпозиций
|
||||
if (uiLogsEnabled) {
|
||||
_debugLogs.value = (_debugLogs.value + logLine).takeLast(50)
|
||||
}
|
||||
}
|
||||
|
||||
fun enableUILogs(enabled: Boolean) {
|
||||
uiLogsEnabled = enabled
|
||||
}
|
||||
|
||||
fun clearLogs() {
|
||||
|
||||
Reference in New Issue
Block a user