mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 05:27:42 +00:00
Fix potential missing recipient crash in profile fetch.
This commit is contained in:
@@ -724,20 +724,21 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
return RecipientReader(cursor)
|
||||
}
|
||||
|
||||
fun getRecords(ids: Collection<RecipientId>): Map<RecipientId, RecipientRecord> {
|
||||
val queries = SqlUtil.buildCollectionQuery(
|
||||
fun getExistingRecords(ids: Collection<RecipientId>): Map<RecipientId, RecipientRecord> {
|
||||
val query = SqlUtil.buildFastCollectionQuery(
|
||||
column = ID,
|
||||
values = ids.map { it.serialize() }
|
||||
)
|
||||
|
||||
val foundRecords = queries.flatMap { query ->
|
||||
readableDatabase.query(TABLE_NAME, null, query.where, query.whereArgs, null, null, null).readToList { cursor ->
|
||||
RecipientTableCursorUtil.getRecord(context, cursor)
|
||||
}
|
||||
}
|
||||
val foundRecords = readableDatabase
|
||||
.select()
|
||||
.from(TABLE_NAME)
|
||||
.where(query.where, query.whereArgs)
|
||||
.run()
|
||||
.readToList { cursor -> RecipientTableCursorUtil.getRecord(context, cursor) }
|
||||
|
||||
val foundIds = foundRecords.map { record -> record.id }
|
||||
val remappedRecords = ids.filterNot { it in foundIds }.map(::findRemappedIdRecord)
|
||||
val remappedRecords = ids.filterNot { it in foundIds }.mapNotNull { findRemappedIdRecord(it) }
|
||||
|
||||
return (foundRecords + remappedRecords).associateBy { it.id }
|
||||
}
|
||||
@@ -750,22 +751,26 @@ open class RecipientTable(context: Context, databaseHelper: SignalDatabase) : Da
|
||||
return if (cursor != null && cursor.moveToNext()) {
|
||||
RecipientTableCursorUtil.getRecord(context, cursor)
|
||||
} else {
|
||||
findRemappedIdRecord(id)
|
||||
findRemappedIdRecordOrThrow(id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findRemappedIdRecord(id: RecipientId): RecipientRecord {
|
||||
private fun findRemappedIdRecord(id: RecipientId): RecipientRecord? {
|
||||
val remapped = RemappedRecords.getInstance().getRecipient(id)
|
||||
|
||||
return if (remapped.isPresent) {
|
||||
Log.w(TAG, "Missing recipient for $id, but found it in the remapped records as ${remapped.get()}")
|
||||
getRecord(remapped.get())
|
||||
} else {
|
||||
throw MissingRecipientException(id)
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
private fun findRemappedIdRecordOrThrow(id: RecipientId): RecipientRecord {
|
||||
return findRemappedIdRecord(id) ?: throw MissingRecipientException(id)
|
||||
}
|
||||
|
||||
fun getRecordForSync(id: RecipientId): RecipientRecord? {
|
||||
val query = "$TABLE_NAME.$ID = ?"
|
||||
val args = arrayOf(id.serialize())
|
||||
|
||||
@@ -121,7 +121,7 @@ class RetrieveProfileJob private constructor(parameters: Parameters, private val
|
||||
.safeBlockingGet()
|
||||
stopwatch.split("responses")
|
||||
|
||||
val localRecords = SignalDatabase.recipients.getRecords(recipientIds)
|
||||
val localRecords = SignalDatabase.recipients.getExistingRecords(recipientIds)
|
||||
Log.d(TAG, "Fetched ${localRecords.size} existing records.")
|
||||
stopwatch.split("disk-fetch")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user