Fix Medium severity performance findings (PERF-17 to PERF-21) (#325)
* Fix Medium severity performance findings (PERF-17 to PERF-21) This commit addresses the following performance findings: - PERF-17: Implemented a message queue in `HermesWsClient` using `ConcurrentLinkedQueue`. If the WebSocket is disconnected, messages are queued and flushed upon a successful connection (`onOpen`). - PERF-18: Added exponential backoff to `safeApiCall` for 5xx and IO exceptions, reducing the load on a struggling server. - PERF-19: Optimized Kanban task filtering by performing `groupBy` upfront inside a `remember` block and passing item keys to `LazyColumn`, avoiding O(C×T) calculation per recomposition. - PERF-20: Updated `getLogs` API in `HermesApiService` to accept `lines` and `limit` query params to truncate logs early, avoiding potential JSON parsing OOMs with large log files. - PERF-21: Optimized drawer entry generation in `Navigation.kt` by grouping navigation items inside a `remember` block. Fixes #282 * Fix Medium severity performance findings (PERF-17 to PERF-21) This commit addresses the following performance findings: - PERF-17: Implemented a message queue in `HermesWsClient` using `ConcurrentLinkedQueue`. If the WebSocket is disconnected, messages are queued and flushed upon a successful connection (`onOpen`). - PERF-18: Added exponential backoff to `safeApiCall` for 5xx and IO exceptions, reducing the load on a struggling server. - PERF-19: Optimized Kanban task filtering by performing `groupBy` upfront inside a `remember` block and passing item keys to `LazyColumn`, avoiding O(C×T) calculation per recomposition. - PERF-20: Updated `getLogs` API in `HermesApiService` to accept `lines` and `limit` query params to truncate logs early, avoiding potential JSON parsing OOMs with large log files. - PERF-21: Optimized drawer entry generation in `Navigation.kt` by grouping navigation items inside a `remember` block. Fixes #282 * Fix Medium severity performance findings (PERF-17 to PERF-21) This commit addresses the following performance findings: - PERF-17: Implemented a message queue in `HermesWsClient` using `ConcurrentLinkedQueue`. If the WebSocket is disconnected, messages are queued and flushed upon a successful connection (`onOpen`). - PERF-18: Added exponential backoff to `safeApiCall` for 5xx and IO exceptions, reducing the load on a struggling server. - PERF-19: Optimized Kanban task filtering by performing `groupBy` upfront inside a `remember` block and passing item keys to `LazyColumn`, avoiding O(C×T) calculation per recomposition. - PERF-20: Updated `getLogs` API in `HermesApiService` to accept `lines` and `limit` query params to truncate logs early, avoiding potential JSON parsing OOMs with large log files. - PERF-21: Optimized drawer entry generation in `Navigation.kt` by grouping navigation items inside a `remember` block. Fixes #282 * fix: resolve ktlint formatting issues in KanbanScreen.kt and Navigation.kt * fix: fix ktlint import ordering in HermesWsClient.kt --------- Co-authored-by: M57 <hy4ri@users.noreply.github.com>
This commit is contained in:
1 parent
42fcf2a14b
commit
d616c56176
7 files changed
+71
-42
No files matched your search
@@ -212,7 +212,10 @@ interface HermesApiService {
|
||||
suspend fun getModelOptions(): Response<ModelOptionsResponse>
|
||||
|
||||
@GET("api/logs")
|
||||
suspend fun getLogs(): Response<LogResponse>
|
||||
suspend fun getLogs(
|
||||
@Query("limit") limit: Int? = null,
|
||||
@Query("lines") lines: Int? = null,
|
||||
): Response<LogResponse>
|
||||
|
||||
@GET("api/dashboard/plugins/hub")
|
||||
suspend fun getPlugins(): Response<PluginsHubResponse>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.m57.hermescontrol.data.remote
|
||||
|
||||
import kotlinx.coroutines.delay
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
|
||||
@@ -68,6 +69,8 @@ suspend inline fun <reified T> safeApiCall(
|
||||
} else {
|
||||
val code = response.code()
|
||||
if (code in 500..599 && attempt < retries) {
|
||||
val backoff = 500L * (1 shl attempt)
|
||||
delay(backoff)
|
||||
continue
|
||||
}
|
||||
return NetworkResult.Failure(mapHttpError(code))
|
||||
@@ -82,6 +85,8 @@ suspend inline fun <reified T> safeApiCall(
|
||||
),
|
||||
)
|
||||
}
|
||||
val backoff = 500L * (1 shl attempt)
|
||||
delay(backoff)
|
||||
} catch (e: Exception) {
|
||||
return NetworkResult.Failure(
|
||||
NetworkError.Unknown(
|
||||
|
||||
Reference in new issue
Block a user