Skip to content

Commit 6799b5b

Browse files
authored
refactor(android): remove obsolete global cache cleanup (#101470)
1 parent a6352f9 commit 6799b5b

8 files changed

Lines changed: 0 additions & 151 deletions

File tree

apps/android/app/src/main/java/ai/openclaw/app/SecurePrefs.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -531,17 +531,6 @@ class SecurePrefs(
531531
defaultValue: Int,
532532
): Int = plainPrefs.getInt(key, defaultValue)
533533

534-
internal fun putPlainString(
535-
key: String,
536-
value: String,
537-
) {
538-
plainPrefs.edit { putString(key, value) }
539-
}
540-
541-
internal fun removePlainKey(key: String) {
542-
plainPrefs.edit { remove(key) }
543-
}
544-
545534
internal fun movePlainString(
546535
sourceKey: String,
547536
destinationKey: String?,

apps/android/app/src/main/java/ai/openclaw/app/chat/ChatCommandOutbox.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,6 @@ interface ChatCommandOutbox {
121121
gatewayId: String,
122122
nowMs: Long,
123123
)
124-
125-
/** Purges every row for all gateways; used when pairing/auth state is reset. */
126-
suspend fun clearAll()
127124
}
128125

129126
@Entity(tableName = "outbox_commands")
@@ -201,9 +198,6 @@ internal interface ChatOutboxDao {
201198

202199
@Query("DELETE FROM outbox_commands WHERE gatewayId = :gatewayId")
203200
suspend fun deleteGateway(gatewayId: String)
204-
205-
@Query("DELETE FROM outbox_commands")
206-
suspend fun deleteAll()
207201
}
208202

209203
/**
@@ -340,9 +334,5 @@ class RoomChatCommandOutbox internal constructor(
340334
)
341335
}
342336

343-
override suspend fun clearAll() {
344-
database.outboxDao().deleteAll()
345-
}
346-
347337
private fun scopedGatewayId(gatewayId: String): String? = gatewayId.trim().takeIf { it.isNotEmpty() }
348338
}

apps/android/app/src/main/java/ai/openclaw/app/chat/ChatController.kt

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,6 @@ class ChatController internal constructor(
280280
scope.launch { publishOutbox() }
281281
}
282282

283-
/** Purges cached transcripts and queued sends after old-scope writes finish. */
284-
internal suspend fun clearTranscriptCache() {
285-
val cache = transcriptCache ?: return
286-
cacheMutationMutex.withLock {
287-
cache.clearAll()
288-
commandOutbox?.clearAll()
289-
}
290-
}
291-
292283
/** Purges cached transcripts and queued sends for one retired authentication scope. */
293284
internal suspend fun clearGatewayCache(gatewayId: String) {
294285
cacheMutationMutex.withLock {

apps/android/app/src/main/java/ai/openclaw/app/chat/ChatTranscriptCache.kt

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,13 @@ import androidx.room.withTransaction
1313
import kotlinx.serialization.builtins.ListSerializer
1414
import kotlinx.serialization.builtins.serializer
1515
import kotlinx.serialization.json.Json
16-
import java.io.File
1716
import java.util.UUID
1817

1918
/** Upper bound of cached session rows per gateway; oldest list positions are evicted on write. */
2019
internal const val MAX_CACHED_SESSIONS = 50
2120

2221
internal const val CHAT_TRANSCRIPT_CACHE_DB_NAME = "chat-transcript-cache.db"
2322

24-
/**
25-
* Deletes the cache database and every SQLite-owned companion file. Only safe while no
26-
* [RoomChatTranscriptCache] is open in this process; used before the node runtime exists.
27-
*/
28-
internal fun deleteChatTranscriptCacheDatabase(context: Context): Boolean = deleteDatabaseFiles(context, CHAT_TRANSCRIPT_CACHE_DB_NAME)
29-
30-
internal fun deleteDatabaseFiles(
31-
context: Context,
32-
databaseName: String,
33-
): Boolean {
34-
val databasePath = context.getDatabasePath(databaseName)
35-
context.deleteDatabase(databaseName)
36-
val fixedFiles =
37-
listOf(
38-
databasePath,
39-
File(databasePath.path + "-journal"),
40-
File(databasePath.path + "-shm"),
41-
File(databasePath.path + "-wal"),
42-
)
43-
if (fixedFiles.any(File::exists)) return false
44-
val parent = databasePath.parentFile ?: return true
45-
val siblings = parent.listFiles() ?: return !parent.exists()
46-
val masterJournalPrefix = databasePath.name + "-mj"
47-
return siblings.none { file -> file.name.startsWith(masterJournalPrefix) }
48-
}
49-
5023
/** Upper bound of cached transcript rows per session; only the newest messages are kept. */
5124
internal const val MAX_CACHED_MESSAGES_PER_SESSION = 200
5225

@@ -85,9 +58,6 @@ interface ChatTranscriptCache {
8558

8659
/** Removes every cached transcript row owned by one gateway identity. */
8760
suspend fun clearGateway(gatewayId: String)
88-
89-
/** Purges every cached row for all gateways; used when pairing/auth state is reset. */
90-
suspend fun clearAll()
9161
}
9262

9363
@Entity(tableName = "cached_sessions", primaryKeys = ["gatewayId", "sessionKey"])
@@ -147,12 +117,6 @@ internal interface ChatCacheDao {
147117
@Query("DELETE FROM cached_messages WHERE gatewayId = :gatewayId")
148118
suspend fun deleteMessages(gatewayId: String)
149119

150-
@Query("DELETE FROM cached_sessions")
151-
suspend fun deleteAllSessions()
152-
153-
@Query("DELETE FROM cached_messages")
154-
suspend fun deleteAllMessages()
155-
156120
@Query("DELETE FROM cached_sessions WHERE gatewayId = :gatewayId AND sessionKey = :sessionKey")
157121
suspend fun deleteSessionRow(
158122
gatewayId: String,
@@ -343,14 +307,6 @@ class RoomChatTranscriptCache internal constructor(
343307
}
344308
}
345309

346-
override suspend fun clearAll() {
347-
val dao = database.dao()
348-
database.withTransaction {
349-
dao.deleteAllSessions()
350-
dao.deleteAllMessages()
351-
}
352-
}
353-
354310
override suspend fun clearGateway(gatewayId: String) {
355311
val gateway = scopedGatewayId(gatewayId) ?: return
356312
val dao = database.dao()

apps/android/app/src/test/java/ai/openclaw/app/chat/ChatControllerOutboxTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,6 @@ class ChatControllerOutboxTest {
131131
}
132132
}
133133
}
134-
135-
override suspend fun clearAll() {
136-
rows.clear()
137-
gatewayIds.clear()
138-
}
139134
}
140135

141136
/** Toggleable gateway seam: records chat.send idempotency keys and echoes them as run ids. */

apps/android/app/src/test/java/ai/openclaw/app/chat/ChatControllerTranscriptCacheTest.kt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ class ChatControllerTranscriptCacheTest {
6060
savedTranscripts.removeAll { it.first == gatewayId }
6161
savedSessions.removeAll { it.first == gatewayId }
6262
}
63-
64-
override suspend fun clearAll() {
65-
transcripts.clear()
66-
sessions = emptyList()
67-
}
6863
}
6964

7065
private fun cachedMessage(

apps/android/app/src/test/java/ai/openclaw/app/chat/RoomChatCommandOutboxTest.kt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -171,16 +171,4 @@ class RoomChatCommandOutboxTest {
171171

172172
assertEquals(listOf("for other"), store.load("gateway-a").map { it.text })
173173
}
174-
175-
@Test
176-
fun clearAllPurgesEveryGatewayScope() =
177-
runTest {
178-
store.enqueueQueued("a command", nowMs = 10, gatewayId = "gateway-a")
179-
store.enqueueQueued("b command", nowMs = 20, gatewayId = "gateway-b")
180-
181-
store.clearAll()
182-
183-
assertEquals(emptyList<ChatOutboxItem>(), store.load("gateway-a"))
184-
assertEquals(emptyList<ChatOutboxItem>(), store.load("gateway-b"))
185-
}
186174
}

apps/android/app/src/test/java/ai/openclaw/app/chat/RoomChatTranscriptCacheTest.kt

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
package ai.openclaw.app.chat
22

3-
import android.content.ContextWrapper
43
import androidx.room.Room
54
import kotlinx.coroutines.test.runTest
65
import org.junit.After
76
import org.junit.Assert.assertEquals
8-
import org.junit.Assert.assertFalse
97
import org.junit.Assert.assertTrue
108
import org.junit.Test
119
import org.junit.runner.RunWith
1210
import org.robolectric.RobolectricTestRunner
1311
import org.robolectric.RuntimeEnvironment
14-
import java.io.File
15-
import java.util.UUID
1612

1713
@RunWith(RobolectricTestRunner::class)
1814
class RoomChatTranscriptCacheTest {
@@ -28,41 +24,6 @@ class RoomChatTranscriptCacheTest {
2824

2925
private fun cache(): RoomChatTranscriptCache = RoomChatTranscriptCache(database = database)
3026

31-
@Test
32-
fun databaseDeleteFailsWhenCompanionFileSurvives() {
33-
val app = RuntimeEnvironment.getApplication()
34-
val databaseName = "chat-cache-delete-test-${UUID.randomUUID()}.db"
35-
val databasePath = app.getDatabasePath(databaseName)
36-
databasePath.parentFile?.mkdirs()
37-
val walFile = File(databasePath.path + "-wal")
38-
walFile.writeText("stale cache")
39-
val noOpDeleteContext =
40-
object : ContextWrapper(app) {
41-
override fun deleteDatabase(name: String): Boolean = true
42-
}
43-
44-
assertFalse(deleteDatabaseFiles(noOpDeleteContext, databaseName))
45-
assertTrue(walFile.exists())
46-
assertTrue(deleteDatabaseFiles(app, databaseName))
47-
assertFalse(walFile.exists())
48-
}
49-
50-
@Test
51-
fun databaseDeleteSucceedsBeforeDatabaseDirectoryExists() {
52-
val app = RuntimeEnvironment.getApplication()
53-
val missingParent = File(app.cacheDir, "missing-database-dir-${UUID.randomUUID()}")
54-
val databasePath = File(missingParent, "chat-cache.db")
55-
val freshInstallContext =
56-
object : ContextWrapper(app) {
57-
override fun getDatabasePath(name: String): File = databasePath
58-
59-
override fun deleteDatabase(name: String): Boolean = true
60-
}
61-
62-
assertFalse(missingParent.exists())
63-
assertTrue(deleteDatabaseFiles(freshInstallContext, databasePath.name))
64-
}
65-
6627
private fun message(
6728
text: String,
6829
role: String = "user",
@@ -276,22 +237,6 @@ class RoomChatTranscriptCacheTest {
276237
assertEquals(listOf("main"), store.loadSessions("gateway-a").map { it.key })
277238
}
278239

279-
@Test
280-
fun clearAllPurgesEveryGatewayScope() =
281-
runTest {
282-
val store = cache()
283-
store.saveSessions("gateway-a", listOf(ChatSessionEntry(key = "main", updatedAtMs = 1)))
284-
store.saveTranscript(gatewayId = "gateway-a", sessionKey = "main", messages = listOf(message("a text")))
285-
store.saveTranscript(gatewayId = "gateway-b", sessionKey = "main", messages = listOf(message("b text")))
286-
287-
store.clearAll()
288-
289-
assertEquals(emptyList<ChatMessage>(), store.loadTranscript("gateway-b", "main"))
290-
assertEquals(emptyList<ChatSessionEntry>(), store.loadSessions("gateway-b"))
291-
assertEquals(emptyList<ChatMessage>(), store.loadTranscript("gateway-a", "main"))
292-
assertEquals(emptyList<ChatSessionEntry>(), store.loadSessions("gateway-a"))
293-
}
294-
295240
@Test
296241
fun blankGatewayIdentityDisablesReadsAndWrites() =
297242
runTest {

0 commit comments

Comments
 (0)