Skip to content

Commit

Permalink
fix clicking the "Send" button would freeze for some hundreds of mill…
Browse files Browse the repository at this point in the history
…iseconds during firing the 1st call and some random calls
  • Loading branch information
sunny-chung committed Nov 9, 2024
1 parent 35f463b commit 95475a7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Optimized
- Request body editor, payload body editor and response body viewer are now able to handle bodies with a size of megabytes without noticeable performance issues.
- Clicking the "Send" button now never freeze for a short while.

## [1.6.0] - 2024-07-22

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,28 @@ class SpringWebClientTransportClient(networkClientManager: NetworkClientManager)

val sentRequestHeaders: MutableList<Pair<String, String>> = mutableListOf()

val client = buildWebClient(
callId = callId,
callData = data,
isSsl = uri.scheme !in setOf("http", "ws"),
httpConfig = httpConfig,
sslConfig = sslConfig,
outgoingBytesFlow = data.outgoingBytes as MutableSharedFlow<RawPayload>,
incomingBytesFlow = data.incomingBytes as MutableSharedFlow<RawPayload>,
http2AccumulatedOutboundDataSerializeLimit = (subprojectConfig.accumulatedOutboundDataStorageLimitPerCall.takeIf { it >= 0 }
?: DEFAULT_ACCUMULATED_DATA_STORAGE_SIZE_LIMIT).toInt(),
http2AccumulatedInboundDataSerializeLimit = (subprojectConfig.accumulatedInboundDataStorageLimitPerCall.takeIf { it >= 0 }
?: DEFAULT_ACCUMULATED_DATA_STORAGE_SIZE_LIMIT).toInt(),
doOnRequestSent = { req ->
log.d { "Req header = ${req.requestHeaders()}" }
sentRequestHeaders += req.requestHeaders().map { e ->
e.toPair()
}
},
)

CoroutineScope(Dispatchers.IO).launch(coroutineExceptionHandler()) {
val client = buildWebClient(
callId = callId,
callData = data,
isSsl = uri.scheme !in setOf("http", "ws"),
httpConfig = httpConfig,
sslConfig = sslConfig,
outgoingBytesFlow = data.outgoingBytes as MutableSharedFlow<RawPayload>,
incomingBytesFlow = data.incomingBytes as MutableSharedFlow<RawPayload>,
http2AccumulatedOutboundDataSerializeLimit = (subprojectConfig.accumulatedOutboundDataStorageLimitPerCall.takeIf { it >= 0 }
?: DEFAULT_ACCUMULATED_DATA_STORAGE_SIZE_LIMIT).toInt(),
http2AccumulatedInboundDataSerializeLimit = (subprojectConfig.accumulatedInboundDataStorageLimitPerCall.takeIf { it >= 0 }
?: DEFAULT_ACCUMULATED_DATA_STORAGE_SIZE_LIMIT).toInt(),
doOnRequestSent = { req ->
log.d { "Req header = ${req.requestHeaders()}" }
sentRequestHeaders += req.requestHeaders().map { e ->
e.toPair()
}
},
)
log.d { "prepared client" }

data.waitForPreparation()
log.d { "Call $callId is prepared" }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,10 @@ sealed class BaseCollectionRepository<T : Document<ID>, ID : DocumentIdentifier>
}
}

open fun readCache(identifier: ID): T? {
return persistenceManager.documentCaches[identifier] as T?
}

private suspend fun readWithoutLock(identifier: ID): T? {
return with(persistenceManager) {
val cache = documentCaches[identifier]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,15 +273,15 @@ fun AppContentView() {
mutableStateOf(null)
}
callDataUpdates // this line forces UI subscribing to call updates
val activeResponse = selectedRequestExampleId?.let { networkClientManager.getResponseByRequestExampleId(it) }
// val activeResponse = selectedRequestExampleId?.let { networkClientManager.getResponseByRequestExampleId(it) }
// var response by remember { mutableStateOf<UserResponse?>(null) }
// if (activeResponse != null && activeResponse.requestId == request?.id && activeResponse.requestExampleId == selectedRequestExampleId) {
// response = activeResponse
// }
val response = runBlocking { // should be fast as it is retrieved from memory
if (selectedSubproject == null || selectedRequestExampleId == null) return@runBlocking null
val response = run {
if (selectedSubproject == null || selectedRequestExampleId == null) return@run null
val di = ResponsesDI(subprojectId = selectedSubproject!!.id)
val resp = responseCollectionRepository.read(di)
val resp = responseCollectionRepository.readCache(di)
?.responsesByRequestExampleId?.get(selectedRequestExampleId)
log.d { "updateResponseView $selectedRequestExampleId" }
resp
Expand Down Expand Up @@ -695,6 +695,8 @@ fun AppContentView() {
}
StatusBarView()
}

log.d { "AppContentView compose end" }
}

fun Modifier.clearFocusOnTap(): Modifier = composed {
Expand Down

0 comments on commit 95475a7

Please sign in to comment.