perf: optimize data loading across Config, System, Profiles, and Billing tabs (#678)

* perf(model): optimize model tab load speed with two-phase fetch and loadQuick

* perf: optimize data loading across Config, System, Profiles, and Billing tabs

* chore: remove leftover bottom nav references and unused updatePrimaryScreens

* style: fix ktlint violations in Config/Profiles/Billing ViewModels

- property/argument-list wrapping for async(...) calls
- multiline-expression wrapping for async blocks
- remove unused import in ConfigViewModel
- break long error-message string literals to stay under 120 cols

---------

Co-authored-by: M57 <Hy4ri@users.noreply.github.com>
This commit is contained in:
M57andM57 authored and GitHub committed 2026-07-22 15:03:30 +03:00
1 parent f7afbfae85
commit 1cca7764cc
7 files changed
+222 -172

No files matched your search

@@ -159,6 +159,53 @@ class SystemViewModel :
}
}
// ── Targeted Data Reloads ──────────────────────────────────────────
fun loadCredentials() {
viewModelScope.launch {
val result = withContext(Dispatchers.IO) { safeApiCall { ApiClient.hermesApi.getCredentialPool() } }
if (result is NetworkResult.Success) {
_uiState.update { it.copy(credentials = result.data.providers ?: emptyList()) }
}
}
}
fun loadHooks() {
viewModelScope.launch {
val result = withContext(Dispatchers.IO) { safeApiCall { ApiClient.hermesApi.getHooks() } }
if (result is NetworkResult.Success) {
_uiState.update { it.copy(hooks = result.data) }
}
}
}
fun loadCurator() {
viewModelScope.launch {
val result = withContext(Dispatchers.IO) { safeApiCall { ApiClient.hermesApi.getCurator() } }
if (result is NetworkResult.Success) {
_uiState.update { it.copy(curator = result.data) }
}
}
}
fun loadMemory() {
viewModelScope.launch {
val result = withContext(Dispatchers.IO) { safeApiCall { ApiClient.hermesApi.getMemory() } }
if (result is NetworkResult.Success) {
_uiState.update { it.copy(memory = result.data) }
}
}
}
fun loadStatus() {
viewModelScope.launch {
val result = withContext(Dispatchers.IO) { safeApiCall { ApiClient.hermesApi.getStatus() } }
if (result is NetworkResult.Success) {
_uiState.update { it.copy(status = result.data) }
}
}
}
// ── Gateway actions ────────────────────────────────────────────────
fun startGateway() {
@@ -182,7 +229,7 @@ class SystemViewModel :
when (result) {
is NetworkResult.Success -> {
_uiState.update { it.copy(toastMessage = "Gateway ${name}ed successfully") }
loadAll()
loadStatus()
}
is NetworkResult.Failure -> {
@@ -249,7 +296,7 @@ class SystemViewModel :
toastMessage = "Curator ${if (!currentlyPaused) "paused" else "resumed"}",
)
}
loadAll()
loadCurator()
}
is NetworkResult.Failure -> {
@@ -277,7 +324,7 @@ class SystemViewModel :
when (result) {
is NetworkResult.Success -> {
_uiState.update { it.copy(toastMessage = "Memory ($target) reset successfully") }
loadAll()
loadMemory()
}
is NetworkResult.Failure -> {
@@ -329,7 +376,7 @@ class SystemViewModel :
toastMessage = "Credential added",
)
}
loadAll()
loadCredentials()
}
is NetworkResult.Failure -> {
@@ -353,7 +400,7 @@ class SystemViewModel :
when (result) {
is NetworkResult.Success -> {
_uiState.update { it.copy(toastMessage = "Credential removed") }
loadAll()
loadCredentials()
}
is NetworkResult.Failure -> {
@@ -561,7 +608,7 @@ class SystemViewModel :
toastMessage = "Hook created",
)
}
loadAll()
loadHooks()
}
is NetworkResult.Failure -> {
@@ -588,7 +635,7 @@ class SystemViewModel :
when (result) {
is NetworkResult.Success -> {
_uiState.update { it.copy(toastMessage = "Hook deleted") }
loadAll()
loadHooks()
}
is NetworkResult.Failure -> {