From 8379eb46e122a60229a895e77d4b9af573857342 Mon Sep 17 00:00:00 2001 From: samosvalishe Date: Wed, 10 Jun 2026 16:06:53 +0300 Subject: [PATCH] =?UTF-8?q?perf(domain):=20=D0=B1=D0=B0=D1=82=D1=87=D0=B8?= =?UTF-8?q?=D1=82=D1=8C=20=D0=B2=D1=8B=D0=B2=D0=BE=D0=B4=20SSH-=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=20=D0=BE=D0=B4=D0=BD=D0=B8=D0=BC?= =?UTF-8?q?=20=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5?= =?UTF-8?q?=D0=BC=20=D0=BB=D0=BE=D0=B3=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/freeturn/app/domain/SshRepository.kt | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/com/freeturn/app/domain/SshRepository.kt b/app/src/main/java/com/freeturn/app/domain/SshRepository.kt index 6c60256..62bbc0c 100644 --- a/app/src/main/java/com/freeturn/app/domain/SshRepository.kt +++ b/app/src/main/java/com/freeturn/app/domain/SshRepository.kt @@ -44,7 +44,8 @@ class SshRepository( private val timeFormatter = DateTimeFormatter.ofPattern("HH:mm:ss") private fun timestamp(): String = LocalTime.now().format(timeFormatter) - private fun appendSshLog(vararg lines: String) { + private fun appendSshLog(lines: List) { + if (lines.isEmpty()) return _sshLog.update { current -> var next = current + lines if (next.size > 500) next = next.drop(next.size - 500) @@ -52,18 +53,23 @@ class SshRepository( } } + private fun appendSshLog(vararg lines: String) = appendSshLog(lines.toList()) + private fun logHeader(label: String, target: String) { appendSshLog("", "=== $label [${timestamp()}] ===", " ssh $target") } private fun logCmdResult(result: CmdResult) { - result.logs.forEach { appendSshLog(it) } - when (result) { - is CmdResult.Ok -> - result.kv.forEach { (k, v) -> appendSshLog(" $k=$v") } - is CmdResult.Err -> - appendSshLog("ERROR: ${result.message}") + // Одним обновлением состояния: построчный append на длинном выводе (журнал + // на 200 строк) дёргал подписчиков UI — бейдж и автоскролл — на каждую строку. + val batch = buildList { + addAll(result.logs) + when (result) { + is CmdResult.Ok -> result.kv.forEach { (k, v) -> add(" $k=$v") } + is CmdResult.Err -> add("ERROR: ${result.message}") + } } + appendSshLog(batch) } private suspend fun runCmd(cfg: SshConfig, label: String, cmd: ServerCommand): CmdResult { @@ -81,7 +87,7 @@ class SshRepository( knownFingerprint = cfg.hostFingerprint.ifEmpty { null }, sshKey = if (cfg.authType == "SSH_KEY") cfg.sshKey else "" ) - result.lines().filter { it.isNotBlank() }.forEach { appendSshLog(it) } + appendSshLog(result.lines().filter { it.isNotBlank() }) return result }