mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-04-21 17:29:32 +01:00
Refactor and improve attachment deduping logic.
This commit is contained in:
committed by
Cody Henthorne
parent
b7ee6bfcb3
commit
6df1a68213
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,7 @@ class MediaTable internal constructor(context: Context?, databaseHelper: SignalD
|
||||
${AttachmentTable.TABLE_NAME}.${AttachmentTable.UPLOAD_TIMESTAMP},
|
||||
${AttachmentTable.TABLE_NAME}.${AttachmentTable.REMOTE_INCREMENTAL_DIGEST},
|
||||
${AttachmentTable.TABLE_NAME}.${AttachmentTable.REMOTE_INCREMENTAL_DIGEST_CHUNK_SIZE},
|
||||
${AttachmentTable.TABLE_NAME}.${AttachmentTable.DATA_HASH},
|
||||
${AttachmentTable.TABLE_NAME}.${AttachmentTable.DATA_HASH_END},
|
||||
${MessageTable.TABLE_NAME}.${MessageTable.TYPE},
|
||||
${MessageTable.TABLE_NAME}.${MessageTable.DATE_SENT},
|
||||
${MessageTable.TABLE_NAME}.${MessageTable.DATE_RECEIVED},
|
||||
@@ -71,13 +71,7 @@ class MediaTable internal constructor(context: Context?, databaseHelper: SignalD
|
||||
${MessageTable.VIEW_ONCE} = 0 AND
|
||||
${MessageTable.STORY_TYPE} = 0 AND
|
||||
${MessageTable.LATEST_REVISION_ID} IS NULL AND
|
||||
(
|
||||
${AttachmentTable.QUOTE} = 0 OR
|
||||
(
|
||||
${AttachmentTable.QUOTE} = 1 AND
|
||||
${AttachmentTable.DATA_HASH} IS NULL
|
||||
)
|
||||
) AND
|
||||
${AttachmentTable.QUOTE} = 0 AND
|
||||
${AttachmentTable.STICKER_PACK_ID} IS NULL AND
|
||||
${MessageTable.TABLE_NAME}.${MessageTable.FROM_RECIPIENT_ID} > 0 AND
|
||||
$THREAD_RECIPIENT_ID > 0
|
||||
|
||||
@@ -79,6 +79,7 @@ import org.thoughtcrime.securesms.database.helpers.migration.V218_RecipientPniSi
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V219_PniPreKeyStores
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V220_PreKeyConstraints
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V221_AddReadColumnToCallEventsTable
|
||||
import org.thoughtcrime.securesms.database.helpers.migration.V222_DataHashRefactor
|
||||
|
||||
/**
|
||||
* Contains all of the database migrations for [SignalDatabase]. Broken into a separate file for cleanliness.
|
||||
@@ -160,10 +161,11 @@ object SignalDatabaseMigrations {
|
||||
218 to V218_RecipientPniSignatureVerified,
|
||||
219 to V219_PniPreKeyStores,
|
||||
220 to V220_PreKeyConstraints,
|
||||
221 to V221_AddReadColumnToCallEventsTable
|
||||
221 to V221_AddReadColumnToCallEventsTable,
|
||||
222 to V222_DataHashRefactor
|
||||
)
|
||||
|
||||
const val DATABASE_VERSION = 221
|
||||
const val DATABASE_VERSION = 222
|
||||
|
||||
@JvmStatic
|
||||
fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.thoughtcrime.securesms.database.helpers.migration
|
||||
|
||||
import android.app.Application
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase
|
||||
|
||||
/**
|
||||
* Adds the new data hash columns and indexes.
|
||||
*/
|
||||
@Suppress("ClassName")
|
||||
object V222_DataHashRefactor : SignalDatabaseMigration {
|
||||
override fun migrate(context: Application, db: SQLiteDatabase, oldVersion: Int, newVersion: Int) {
|
||||
db.execSQL("DROP INDEX attachment_data_hash_index")
|
||||
db.execSQL("ALTER TABLE attachment DROP COLUMN data_hash")
|
||||
|
||||
db.execSQL("ALTER TABLE attachment ADD COLUMN data_hash_start TEXT DEFAULT NULL")
|
||||
db.execSQL("ALTER TABLE attachment ADD COLUMN data_hash_end TEXT DEFAULT NULL")
|
||||
db.execSQL("CREATE INDEX attachment_data_hash_start_index ON attachment (data_hash_start)")
|
||||
db.execSQL("CREATE INDEX attachment_data_hash_end_index ON attachment (data_hash_end)")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user