mirror of
https://github.com/meshtastic/Meshtastic-Android.git
synced 2026-04-20 22:23:37 +00:00
feat: add retention period to meshLog. Defaults to 7 days, with a settings dropdown to change (#4078)
This commit is contained in:
parent
dc9e51f18f
commit
6f338c4cde
12 changed files with 396 additions and 8 deletions
|
|
@ -27,6 +27,7 @@ import kotlinx.coroutines.withContext
|
|||
import org.meshtastic.core.database.DatabaseManager
|
||||
import org.meshtastic.core.database.entity.MeshLog
|
||||
import org.meshtastic.core.di.CoroutineDispatchers
|
||||
import org.meshtastic.core.prefs.meshlog.MeshLogPrefs
|
||||
import org.meshtastic.proto.MeshProtos
|
||||
import org.meshtastic.proto.MeshProtos.MeshPacket
|
||||
import org.meshtastic.proto.Portnums
|
||||
|
|
@ -39,10 +40,16 @@ class MeshLogRepository
|
|||
constructor(
|
||||
private val dbManager: DatabaseManager,
|
||||
private val dispatchers: CoroutineDispatchers,
|
||||
private val meshLogPrefs: MeshLogPrefs,
|
||||
) {
|
||||
fun getAllLogs(maxItems: Int = MAX_ITEMS): Flow<List<MeshLog>> =
|
||||
dbManager.currentDb.flatMapLatest { it.meshLogDao().getAllLogs(maxItems) }.flowOn(dispatchers.io).conflate()
|
||||
|
||||
fun getAllLogsUnbounded(): Flow<List<MeshLog>> = dbManager.currentDb
|
||||
.flatMapLatest { it.meshLogDao().getAllLogs(Int.MAX_VALUE) }
|
||||
.flowOn(dispatchers.io)
|
||||
.conflate()
|
||||
|
||||
fun getAllLogsInReceiveOrder(maxItems: Int = MAX_ITEMS): Flow<List<MeshLog>> = dbManager.currentDb
|
||||
.flatMapLatest { it.meshLogDao().getAllLogsInReceiveOrder(maxItems) }
|
||||
.flowOn(dispatchers.io)
|
||||
|
|
@ -134,8 +141,10 @@ constructor(
|
|||
.mapLatest { list -> list.firstOrNull { it.myNodeInfo != null }?.myNodeInfo }
|
||||
.flowOn(dispatchers.io)
|
||||
|
||||
suspend fun insert(log: MeshLog) =
|
||||
withContext(dispatchers.io) { dbManager.currentDb.value.meshLogDao().insert(log) }
|
||||
suspend fun insert(log: MeshLog) = withContext(dispatchers.io) {
|
||||
if (!meshLogPrefs.loggingEnabled) return@withContext
|
||||
dbManager.currentDb.value.meshLogDao().insert(log)
|
||||
}
|
||||
|
||||
suspend fun deleteAll() = withContext(dispatchers.io) { dbManager.currentDb.value.meshLogDao().deleteAll() }
|
||||
|
||||
|
|
@ -145,6 +154,19 @@ constructor(
|
|||
suspend fun deleteLogs(nodeNum: Int, portNum: Int) =
|
||||
withContext(dispatchers.io) { dbManager.currentDb.value.meshLogDao().deleteLogs(nodeNum, portNum) }
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
suspend fun deleteLogsOlderThan(retentionDays: Int) = withContext(dispatchers.io) {
|
||||
if (retentionDays == MeshLogPrefs.NEVER_CLEAR_RETENTION_DAYS) return@withContext
|
||||
|
||||
val cutoffTimestamp =
|
||||
if (retentionDays == MeshLogPrefs.ONE_HOUR_RETENTION_DAYS) {
|
||||
System.currentTimeMillis() - (60 * 60 * 1000L)
|
||||
} else {
|
||||
System.currentTimeMillis() - (retentionDays * 24 * 60 * 60 * 1000L)
|
||||
}
|
||||
dbManager.currentDb.value.meshLogDao().deleteOlderThan(cutoffTimestamp)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val MAX_ITEMS = 500
|
||||
private const val MAX_MESH_PACKETS = 10000
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue