Decrease db thrashing when starting expiration timers for messages.

This commit is contained in:
Cody Henthorne
2023-10-11 16:14:08 -04:00
parent 05296e3d9b
commit 6a6b80cce2
6 changed files with 51 additions and 28 deletions

View File

@@ -49,10 +49,6 @@ public abstract class DatabaseTable {
protected void notifyConversationListeners(Set<Long> threadIds) {
ApplicationDependencies.getDatabaseObserver().notifyConversationListeners(threadIds);
for (long threadId : threadIds) {
notifyConversationListeners(threadId);
}
}
protected void notifyConversationListeners(long threadId) {

View File

@@ -2186,27 +2186,19 @@ open class MessageTable(context: Context?, databaseHelper: SignalDatabase) : Dat
@JvmOverloads
fun markExpireStarted(id: Long, startedTimestamp: Long = System.currentTimeMillis()) {
markExpireStarted(setOf(id), startedTimestamp)
markExpireStarted(setOf(id to startedTimestamp))
}
fun markExpireStarted(ids: Collection<Long>, startedAtTimestamp: Long) {
var threadId: Long = -1
fun markExpireStarted(ids: Collection<kotlin.Pair<Long, Long>>) {
writableDatabase.withinTransaction { db ->
for (id in ids) {
for ((id, startedAtTimestamp) in ids) {
db.update(TABLE_NAME)
.values(EXPIRE_STARTED to startedAtTimestamp)
.where("$ID = ? AND ($EXPIRE_STARTED = 0 OR $EXPIRE_STARTED > ?)", id, startedAtTimestamp)
.run()
if (threadId < 0) {
threadId = getThreadIdForMessage(id)
}
ApplicationDependencies.getDatabaseObserver().notifyMessageUpdateObservers(MessageId(id))
}
threads.update(threadId, false)
}
notifyConversationListeners(threadId)
}
fun markAsNotified(id: Long) {