fix(android/diagnostics): keep uploader drain within ReturnCount gate
android / Build + lint + test (push) Failing after 2m28s
android / Build + lint + test (push) Failing after 2m28s
drainSafe/drain each had 3 returns (detekt ReturnCount ≤ 2). Collapse the guard clauses and convert drain's loop to a `more` flag — same behavior, zero/two returns. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01K55iTxn95BtshocgdE1shW
This commit is contained in:
+11
-8
@@ -70,8 +70,10 @@ class DiagnosticsUploader @Inject constructor(
|
|||||||
|
|
||||||
/** Coalesces concurrent triggers via tryLock — a drain in flight wins. */
|
/** Coalesces concurrent triggers via tryLock — a drain in flight wins. */
|
||||||
private suspend fun drainSafe() {
|
private suspend fun drainSafe() {
|
||||||
if (authStore.sessionCookie.value.isNullOrEmpty()) return
|
val clientId = authStore.clientId.value
|
||||||
val clientId = authStore.clientId.value ?: return
|
// Signed out / no client id yet → nothing to do. Single guard keeps
|
||||||
|
// the return count within the detekt gate.
|
||||||
|
if (authStore.sessionCookie.value.isNullOrEmpty() || clientId == null) return
|
||||||
if (!mutex.tryLock()) return
|
if (!mutex.tryLock()) return
|
||||||
try {
|
try {
|
||||||
drain(clientId)
|
drain(clientId)
|
||||||
@@ -81,13 +83,14 @@ class DiagnosticsUploader @Inject constructor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun drain(clientId: String) {
|
private suspend fun drain(clientId: String) {
|
||||||
while (true) {
|
var more = true
|
||||||
|
while (more) {
|
||||||
val batch = runCatching { dao.takeBatch(BATCH_SIZE) }.getOrNull().orEmpty()
|
val batch = runCatching { dao.takeBatch(BATCH_SIZE) }.getOrNull().orEmpty()
|
||||||
if (batch.isEmpty()) return
|
val sent = batch.isNotEmpty() && runCatching { upload(clientId, batch) }.isSuccess
|
||||||
val sent = runCatching { upload(clientId, batch) }.isSuccess
|
if (sent) runCatching { dao.deleteByIds(batch.map { it.id }) }
|
||||||
if (!sent) return // leave rows for the next trigger
|
// Keep going only while a full batch sent cleanly; otherwise stop
|
||||||
runCatching { dao.deleteByIds(batch.map { it.id }) }
|
// (empty buffer, or a failure to retry on the next trigger).
|
||||||
if (batch.size < BATCH_SIZE) return
|
more = sent && batch.size >= BATCH_SIZE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user