mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-23 02:10:44 +01:00
Add additional thread delete performance improvements.
This commit is contained in:
committed by
jeffrey-signal
parent
b0b2c32a6f
commit
02ce6c62a8
@@ -15,6 +15,7 @@ import org.signal.benchmark.setup.Generator
|
||||
import org.signal.benchmark.setup.Harness
|
||||
import org.signal.benchmark.setup.OtherClient
|
||||
import org.signal.core.util.ThreadUtil
|
||||
import org.thoughtcrime.securesms.dependencies.AppDependencies
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.TestDbUtils
|
||||
@@ -152,17 +153,22 @@ class BenchmarkCommandReceiver : BroadcastReceiver() {
|
||||
}
|
||||
|
||||
private fun handleDeleteThread() {
|
||||
val threadId = SignalDatabase.threads.getRecentConversationList(1, false, false).use { cursor ->
|
||||
val threadId = SignalDatabase.rawDatabase.rawQuery("SELECT thread_id, COUNT(*) AS msg_count FROM message GROUP BY thread_id ORDER BY msg_count DESC LIMIT 1").use { cursor ->
|
||||
if (cursor.moveToFirst()) {
|
||||
cursor.getLong(cursor.getColumnIndexOrThrow("_id"))
|
||||
val id = cursor.getLong(0)
|
||||
val count = cursor.getLong(1)
|
||||
Log.i(TAG, "Found largest thread $id with $count messages")
|
||||
id
|
||||
} else {
|
||||
Log.w(TAG, "No active threads found for deletion benchmark")
|
||||
Log.w(TAG, "No threads found for deletion benchmark")
|
||||
return
|
||||
}
|
||||
}
|
||||
Log.i(TAG, "Deleting thread $threadId")
|
||||
val recipientName = SignalDatabase.threads.getRecipientForThreadId(threadId)
|
||||
?.getDisplayName(AppDependencies.application) ?: "unknown"
|
||||
Log.i(TAG, "Deleting thread $threadId (recipient: $recipientName)")
|
||||
SignalDatabase.threads.deleteConversation(threadId, syncThreadDelete = false)
|
||||
Log.i(TAG, "Thread $threadId deleted")
|
||||
Log.i(TAG, "Thread $threadId deleted (recipient: $recipientName)")
|
||||
}
|
||||
|
||||
private fun getOutgoingGroupMessageTimestamps(): List<Long> {
|
||||
|
||||
@@ -10,16 +10,31 @@ import androidx.compose.runtime.setValue
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import org.signal.benchmark.setup.Harness
|
||||
import org.signal.benchmark.setup.TestMessages
|
||||
import org.signal.benchmark.setup.TestUsers
|
||||
import org.signal.core.models.ServiceId.PNI
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.thoughtcrime.securesms.BaseActivity
|
||||
import org.thoughtcrime.securesms.backup.v2.BackupRepository
|
||||
import org.thoughtcrime.securesms.crypto.ProfileKeyUtil
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase
|
||||
import org.thoughtcrime.securesms.database.TestDbUtils
|
||||
import org.thoughtcrime.securesms.database.model.databaseprotos.RestoreDecisionState
|
||||
import org.thoughtcrime.securesms.keyvalue.SignalStore
|
||||
import org.thoughtcrime.securesms.keyvalue.Skipped
|
||||
import org.thoughtcrime.securesms.mms.OutgoingMessage
|
||||
import org.thoughtcrime.securesms.profiles.ProfileName
|
||||
import org.thoughtcrime.securesms.recipients.Recipient
|
||||
import org.thoughtcrime.securesms.registration.util.RegistrationUtil
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
|
||||
class BenchmarkSetupActivity : BaseActivity() {
|
||||
|
||||
companion object {
|
||||
private val TAG = Log.tag(BenchmarkSetupActivity::class)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
@@ -43,6 +58,7 @@ class BenchmarkSetupActivity : BaseActivity() {
|
||||
"group-read-receipt" -> setupGroupReceipt(enableReadReceipts = true)
|
||||
"thread-delete" -> setupThreadDelete()
|
||||
"thread-delete-group" -> setupThreadDeleteGroup()
|
||||
"backup-restore" -> setupBackupRestore()
|
||||
}
|
||||
setupComplete = true
|
||||
}
|
||||
@@ -151,6 +167,35 @@ class BenchmarkSetupActivity : BaseActivity() {
|
||||
SignalDatabase.threads.update(threadId, true)
|
||||
}
|
||||
|
||||
private fun setupBackupRestore() {
|
||||
TestUsers.setupSelf()
|
||||
|
||||
val profileKey = ProfileKeyUtil.getSelfProfileKey()
|
||||
val selfData = BackupRepository.SelfData(
|
||||
aci = Harness.SELF_ACI,
|
||||
pni = SignalStore.account.requirePni(),
|
||||
e164 = Harness.SELF_E164,
|
||||
profileKey = profileKey
|
||||
)
|
||||
|
||||
val backupBytes = assets.open("backups/backup.binproto").use { it.readBytes() }
|
||||
Log.i(TAG, "Read ${backupBytes.size} bytes from backup asset")
|
||||
|
||||
val result = BackupRepository.importPlaintextTest(
|
||||
length = backupBytes.size.toLong(),
|
||||
inputStreamFactory = { backupBytes.inputStream() },
|
||||
selfData = selfData
|
||||
)
|
||||
|
||||
Log.i(TAG, "Backup import result: $result")
|
||||
|
||||
SignalStore.svr.optOut()
|
||||
SignalStore.registration.restoreDecisionState = RestoreDecisionState.Skipped
|
||||
SignalDatabase.recipients.setProfileKey(Recipient.self().id, profileKey)
|
||||
SignalDatabase.recipients.setProfileName(Recipient.self().id, ProfileName.fromParts("Tester", "McTesterson"))
|
||||
RegistrationUtil.maybeMarkRegistrationComplete()
|
||||
}
|
||||
|
||||
private fun setupGroupReceipt(includeMsl: Boolean = false, enableReadReceipts: Boolean = false) {
|
||||
TestUsers.setupSelf()
|
||||
val groupId = TestUsers.setupGroup()
|
||||
|
||||
Reference in New Issue
Block a user