Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ class SaasBahuSammelanRepo @Inject constructor(
Log.e("AHJAHA",body)
val adapter = moshi.adapter(SaasBahuSammelanGetAllResponse::class.java)
val parsed = adapter.fromJson(body) ?: return@withContext
val unsyncedRecords = saasBahuDao.getBySyncState(SyncState.UNSYNCED)
saasBahuDao.clearAll()
Comment on lines +169 to 170

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | πŸ”΄ Critical | πŸ—οΈ Heavy lift

Make the destructive refresh atomic to fully eliminate offline data loss.

If anything throws after Line 170 and before Line 204 (parse/insert/null assertion, cancellation, etc.), the cached UNSYNCED records are never restored and local offline work is still lost. Please wrap fetch-unsynced β†’ clear β†’ server insert β†’ restore in one Room transaction (or minimally restore in finally as a fallback).

Also applies to: 204-206

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@app/src/main/java/org/piramalswasthya/sakhi/repositories/SaasBahuSammelanRepo.kt`
around lines 169 - 170, Wrap the destructive refresh (fetching unsyncedRecords
via saasBahuDao.getBySyncState, saasBahuDao.clearAll, server inserts/parsing and
the subsequent restore) in a single Room transaction or at minimum ensure
unsyncedRecords are restored in a finally block; specifically, use your
RoomDatabase.runInTransaction { ... } around the sequence that calls
saasBahuDao.getBySyncState and saasBahuDao.clearAll and the insert calls, or
enclose clearAll + server insert in try { ... } catch { throw } finally { if
(unsyncedRecords.isNotEmpty()) saasBahuDao.insertAll(unsyncedRecords) } so that
any exception/cancellation won’t permanently lose the cached UNSYNCED records.

parsed.data?.forEach { item ->
val imageBase64List = item.meetingImages ?: emptyList()
Expand Down Expand Up @@ -200,6 +201,9 @@ class SaasBahuSammelanRepo @Inject constructor(

saasBahuDao.insertSammelan(entity)
}
unsyncedRecords.forEach {
saasBahuDao.insertSammelan(it)
}
}


Expand Down