Utilize timestamp from table instead of relying on getCurrentMillis.

This commit is contained in:
Alex Hart
2023-09-25 15:17:12 -03:00
committed by Cody Henthorne
parent fde0f3bba1
commit f5215d715a
2 changed files with 15 additions and 4 deletions

View File

@@ -94,10 +94,10 @@ class CallLogRepository(
fun deleteAllCallLogsOnOrBeforeNow(): Single<Int> { fun deleteAllCallLogsOnOrBeforeNow(): Single<Int> {
return Single.fromCallable { return Single.fromCallable {
SignalDatabase.rawDatabase.withinTransaction { SignalDatabase.rawDatabase.withinTransaction {
val now = System.currentTimeMillis() val latestTimestamp = SignalDatabase.calls.getLatestTimestamp()
SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(now) SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(latestTimestamp)
SignalDatabase.callLinks.deleteNonAdminCallLinksOnOrBefore(now) SignalDatabase.callLinks.deleteNonAdminCallLinksOnOrBefore(latestTimestamp)
ApplicationDependencies.getJobManager().add(CallLogEventSendJob.forClearHistory(now)) ApplicationDependencies.getJobManager().add(CallLogEventSendJob.forClearHistory(latestTimestamp))
} }
SignalDatabase.callLinks.getAllAdminCallLinksExcept(emptySet()) SignalDatabase.callLinks.getAllAdminCallLinksExcept(emptySet())

View File

@@ -806,6 +806,17 @@ class CallTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTabl
.run() .run()
} }
/**
* Gets the most recent timestamp from the [TIMESTAMP] column
*/
fun getLatestTimestamp(): Long {
val statement = """
SELECT $TIMESTAMP FROM $TABLE_NAME ORDER BY $TIMESTAMP DESC LIMIT 1
""".trimIndent()
return readableDatabase.query(statement).readToSingleLong(-1)
}
fun deleteNonAdHocCallEventsOnOrBefore(timestamp: Long) { fun deleteNonAdHocCallEventsOnOrBefore(timestamp: Long) {
val messageIdsOnOrBeforeTimestamp = """ val messageIdsOnOrBeforeTimestamp = """
SELECT $MESSAGE_ID FROM $TABLE_NAME WHERE $TIMESTAMP <= $timestamp AND $MESSAGE_ID IS NOT NULL SELECT $MESSAGE_ID FROM $TABLE_NAME WHERE $TIMESTAMP <= $timestamp AND $MESSAGE_ID IS NOT NULL