Optimize thread ID DB query.
This commit is contained in:
parent
39fbbe896f
commit
d6fd6cb5a3
1 changed files with 0 additions and 36 deletions
|
@ -3,7 +3,6 @@ package org.thoughtcrime.securesms.database
|
|||
import android.content.Context
|
||||
import android.database.Cursor
|
||||
import androidx.core.content.contentValuesOf
|
||||
import org.signal.core.util.delete
|
||||
import org.signal.core.util.logging.Log
|
||||
import org.signal.core.util.readToList
|
||||
import org.signal.core.util.requireLong
|
||||
|
@ -13,7 +12,6 @@ import org.thoughtcrime.securesms.database.RemappedRecordTables.SharedColumns.ID
|
|||
import org.thoughtcrime.securesms.database.RemappedRecordTables.SharedColumns.NEW_ID
|
||||
import org.thoughtcrime.securesms.database.RemappedRecordTables.SharedColumns.OLD_ID
|
||||
import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import java.util.HashMap
|
||||
|
||||
/**
|
||||
* The backing datastore for [RemappedRecords]. See that class for more details.
|
||||
|
@ -55,8 +53,6 @@ class RemappedRecordTables internal constructor(context: Context?, databaseHelpe
|
|||
}
|
||||
|
||||
fun getAllRecipientMappings(): Map<RecipientId, RecipientId> {
|
||||
clearInvalidRecipientMappings()
|
||||
|
||||
val recipientMap: MutableMap<RecipientId, RecipientId> = HashMap()
|
||||
|
||||
readableDatabase.withinTransaction { db ->
|
||||
|
@ -72,8 +68,6 @@ class RemappedRecordTables internal constructor(context: Context?, databaseHelpe
|
|||
}
|
||||
|
||||
fun getAllThreadMappings(): Map<Long, Long> {
|
||||
clearInvalidThreadMappings()
|
||||
|
||||
val threadMap: MutableMap<Long, Long> = HashMap()
|
||||
|
||||
readableDatabase.withinTransaction { db ->
|
||||
|
@ -95,7 +89,6 @@ class RemappedRecordTables internal constructor(context: Context?, databaseHelpe
|
|||
}
|
||||
|
||||
fun getAllRecipients(): Cursor {
|
||||
clearInvalidRecipientMappings()
|
||||
return readableDatabase
|
||||
.select()
|
||||
.from(Recipients.TABLE_NAME)
|
||||
|
@ -103,7 +96,6 @@ class RemappedRecordTables internal constructor(context: Context?, databaseHelpe
|
|||
}
|
||||
|
||||
fun getAllThreads(): Cursor {
|
||||
clearInvalidThreadMappings()
|
||||
return readableDatabase
|
||||
.select()
|
||||
.from(Threads.TABLE_NAME)
|
||||
|
@ -130,33 +122,5 @@ class RemappedRecordTables internal constructor(context: Context?, databaseHelpe
|
|||
databaseHelper.signalWritableDatabase.insert(table, null, values)
|
||||
}
|
||||
|
||||
/**
|
||||
* The old_id should never exist -- this class is intended to remap from IDs that were deleted.
|
||||
*/
|
||||
private fun clearInvalidRecipientMappings() {
|
||||
val count = writableDatabase
|
||||
.delete(Recipients.TABLE_NAME)
|
||||
.where("$OLD_ID IN (SELECT ${RecipientTable.ID} FROM ${RecipientTable.TABLE_NAME})")
|
||||
.run()
|
||||
|
||||
if (count > 0) {
|
||||
Log.w(TAG, "Deleted $count invalid recipient mappings!", true)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The old_id should never exist -- this class is intended to remap from IDs that were deleted.
|
||||
*/
|
||||
private fun clearInvalidThreadMappings() {
|
||||
val count = writableDatabase
|
||||
.delete(Threads.TABLE_NAME)
|
||||
.where("$OLD_ID IN (SELECT ${ThreadTable.ID} FROM ${ThreadTable.TABLE_NAME})")
|
||||
.run()
|
||||
|
||||
if (count > 0) {
|
||||
Log.w(TAG, "Deleted $count invalid thread mappings!", true)
|
||||
}
|
||||
}
|
||||
|
||||
private class Mapping(val oldId: Long, val newId: Long)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue