Improve cold start performance.

This commit is contained in:
Cody Henthorne
2022-07-21 12:29:58 -04:00
parent d159a0482a
commit fe6058e0df
28 changed files with 82 additions and 97 deletions

View File

@@ -2892,7 +2892,7 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
*/
fun getRecipientsForRoutineProfileFetch(lastInteractionThreshold: Long, lastProfileFetchThreshold: Long, limit: Int): List<RecipientId> {
val threadDatabase = threads
val recipientsWithinInteractionThreshold: MutableSet<Recipient> = LinkedHashSet()
val recipientsWithinInteractionThreshold: MutableSet<RecipientId> = LinkedHashSet()
threadDatabase.readerFor(threadDatabase.getRecentPushConversationList(-1, false)).use { reader ->
var record: ThreadRecord? = reader.next
@@ -2900,15 +2900,16 @@ open class RecipientDatabase(context: Context, databaseHelper: SignalDatabase) :
while (record != null && record.date > lastInteractionThreshold) {
val recipient = Recipient.resolved(record.recipient.id)
if (recipient.isGroup) {
recipientsWithinInteractionThreshold.addAll(recipient.participants)
recipientsWithinInteractionThreshold.addAll(recipient.participantIds)
} else {
recipientsWithinInteractionThreshold.add(recipient)
recipientsWithinInteractionThreshold.add(recipient.id)
}
record = reader.next
}
}
return recipientsWithinInteractionThreshold
return Recipient.resolvedList(recipientsWithinInteractionThreshold)
.asSequence()
.filterNot { it.isSelf }
.filter { it.lastProfileFetchTime < lastProfileFetchThreshold }
.take(limit)