mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-09-19 16:24:41 +01:00
Reduce usage of rawDatabase.
This commit is contained in:
+1
-1
@@ -207,7 +207,7 @@ class EditMessageSyncProcessorTest {
|
||||
}
|
||||
|
||||
fun cleanup() {
|
||||
SignalDatabase.rawDatabase.withinTransaction { db ->
|
||||
SignalDatabase.writableDatabase.withinTransaction { db ->
|
||||
SignalDatabase.threads.deleteAllConversations()
|
||||
db.execSQL("DELETE FROM sqlite_sequence WHERE name = '${MessageTable.TABLE_NAME}'")
|
||||
db.execSQL("DELETE FROM sqlite_sequence WHERE name = '${ThreadTable.TABLE_NAME}'")
|
||||
|
||||
+1
-1
@@ -516,7 +516,7 @@ class SyncMessageProcessorTest_synchronizeDeleteForMe {
|
||||
SignalDatabase.messages.deleteMessage(messageId = oneToOnePlaceHolderMessage, threadId = aliceThreadId, notify = false, updateThread = false)
|
||||
SignalDatabase.messages.deleteMessage(messageId = groupPlaceholderMessage, threadId = aliceThreadId, notify = false, updateThread = false)
|
||||
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
assertThat(SignalDatabase.messages.getMessageCountForThread(aliceThreadId)).isEqualTo(16)
|
||||
assertThat(SignalDatabase.messages.getMessageCountForThread(groupThreadId)).isEqualTo(10)
|
||||
}
|
||||
|
||||
@@ -604,7 +604,7 @@ object BackupRepository {
|
||||
}
|
||||
|
||||
// We make a copy of the database within a transaction to ensure that no writes occur while we're copying the file
|
||||
return SignalDatabase.rawDatabase.withinTransaction {
|
||||
return SignalDatabase.writableDatabase.withinTransaction {
|
||||
val context = AppDependencies.application
|
||||
|
||||
val existingDbFile = context.getDatabasePath(SignalDatabase.DATABASE_NAME)
|
||||
@@ -898,7 +898,7 @@ object BackupRepository {
|
||||
eventTimer.emit("header")
|
||||
|
||||
// We're using a snapshot, so the transaction is more for perf than correctness
|
||||
dbSnapshot.rawWritableDatabase.withinTransaction {
|
||||
dbSnapshot.signalWritableDatabase.withinTransaction {
|
||||
progressEmitter?.onAccount()
|
||||
AccountDataArchiveProcessor.export(dbSnapshot, signalStoreSnapshot, exportState) { frame ->
|
||||
writer.write(frame)
|
||||
@@ -1164,19 +1164,19 @@ object BackupRepository {
|
||||
// SQLite optimizes deletes if there's no foreign keys, triggers, or WHERE clause, so that's the environment we're gonna create.
|
||||
|
||||
Log.d(TAG, "[import] Disabling foreign keys...")
|
||||
SignalDatabase.rawDatabase.forceForeignKeyConstraintsEnabled(false)
|
||||
SignalDatabase.writableDatabase.forceForeignKeyConstraintsEnabled(false)
|
||||
|
||||
Log.d(TAG, "[import] Acquiring transaction...")
|
||||
SignalDatabase.rawDatabase.beginTransaction()
|
||||
SignalDatabase.writableDatabase.beginTransaction()
|
||||
|
||||
Log.d(TAG, "[import] Inside transaction.")
|
||||
stopwatch.split("get-transaction")
|
||||
|
||||
Log.d(TAG, "[import] --- Dropping all indices ---")
|
||||
val indexMetadata = SignalDatabase.rawDatabase.getAllIndexDefinitions()
|
||||
val indexMetadata = SignalDatabase.writableDatabase.getAllIndexDefinitions()
|
||||
for (index in indexMetadata) {
|
||||
Log.d(TAG, "[import] Dropping index ${index.name}...")
|
||||
SignalDatabase.rawDatabase.execSQL("DROP INDEX IF EXISTS ${index.name}")
|
||||
SignalDatabase.writableDatabase.execSQL("DROP INDEX IF EXISTS ${index.name}")
|
||||
}
|
||||
stopwatch.split("drop-indices")
|
||||
|
||||
@@ -1185,10 +1185,10 @@ object BackupRepository {
|
||||
}
|
||||
|
||||
Log.d(TAG, "[import] --- Dropping all triggers ---")
|
||||
val triggerMetadata = SignalDatabase.rawDatabase.getAllTriggerDefinitions()
|
||||
val triggerMetadata = SignalDatabase.writableDatabase.getAllTriggerDefinitions()
|
||||
for (trigger in triggerMetadata) {
|
||||
Log.d(TAG, "[import] Dropping trigger ${trigger.name}...")
|
||||
SignalDatabase.rawDatabase.execSQL("DROP TRIGGER IF EXISTS ${trigger.name}")
|
||||
SignalDatabase.writableDatabase.execSQL("DROP TRIGGER IF EXISTS ${trigger.name}")
|
||||
}
|
||||
stopwatch.split("drop-triggers")
|
||||
|
||||
@@ -1207,7 +1207,7 @@ object BackupRepository {
|
||||
add(SessionTable.TABLE_NAME)
|
||||
}
|
||||
}
|
||||
val tableMetadata = SignalDatabase.rawDatabase.getAllTableDefinitions().filter { !it.name.startsWith(SearchTable.FTS_TABLE_NAME + "_") }
|
||||
val tableMetadata = SignalDatabase.writableDatabase.getAllTableDefinitions().filter { !it.name.startsWith(SearchTable.FTS_TABLE_NAME + "_") }
|
||||
for (table in tableMetadata) {
|
||||
if (skipTables.contains(table.name)) {
|
||||
Log.d(TAG, "[import] Skipping drop/create of table ${table.name}")
|
||||
@@ -1215,10 +1215,10 @@ object BackupRepository {
|
||||
}
|
||||
|
||||
Log.d(TAG, "[import] Dropping table ${table.name}...")
|
||||
SignalDatabase.rawDatabase.execSQL("DROP TABLE IF EXISTS ${table.name}")
|
||||
SignalDatabase.writableDatabase.execSQL("DROP TABLE IF EXISTS ${table.name}")
|
||||
|
||||
Log.d(TAG, "[import] Creating table ${table.name}...")
|
||||
SignalDatabase.rawDatabase.execSQL(table.statement)
|
||||
SignalDatabase.writableDatabase.execSQL(table.statement)
|
||||
}
|
||||
|
||||
RecipientId.clearCache()
|
||||
@@ -1340,14 +1340,14 @@ object BackupRepository {
|
||||
Log.d(TAG, "[import] --- Recreating indices ---")
|
||||
for (index in indexMetadata) {
|
||||
Log.d(TAG, "[import] Creating index ${index.name}...")
|
||||
SignalDatabase.rawDatabase.execSQL(index.statement)
|
||||
SignalDatabase.writableDatabase.execSQL(index.statement)
|
||||
}
|
||||
stopwatch.split("recreate-indices")
|
||||
|
||||
Log.d(TAG, "[import] --- Recreating triggers ---")
|
||||
for (trigger in triggerMetadata) {
|
||||
Log.d(TAG, "[import] Creating trigger ${trigger.name}...")
|
||||
SignalDatabase.rawDatabase.execSQL(trigger.statement)
|
||||
SignalDatabase.writableDatabase.execSQL(trigger.statement)
|
||||
}
|
||||
stopwatch.split("recreate-triggers")
|
||||
|
||||
@@ -1357,17 +1357,17 @@ object BackupRepository {
|
||||
}
|
||||
stopwatch.split("thread-updates")
|
||||
|
||||
val foreignKeyViolations = SignalDatabase.rawDatabase.getForeignKeyViolations()
|
||||
val foreignKeyViolations = SignalDatabase.writableDatabase.getForeignKeyViolations()
|
||||
if (foreignKeyViolations.isNotEmpty()) {
|
||||
throw IllegalStateException("Foreign key check failed! Violations: $foreignKeyViolations")
|
||||
}
|
||||
stopwatch.split("fk-check")
|
||||
|
||||
SignalDatabase.rawDatabase.setTransactionSuccessful()
|
||||
SignalDatabase.writableDatabase.setTransactionSuccessful()
|
||||
transactionSuccessful = true
|
||||
} finally {
|
||||
if (SignalDatabase.rawDatabase.inTransaction()) {
|
||||
SignalDatabase.rawDatabase.endTransaction()
|
||||
if (SignalDatabase.writableDatabase.inTransaction()) {
|
||||
SignalDatabase.writableDatabase.endTransaction()
|
||||
}
|
||||
|
||||
if (!transactionSuccessful) {
|
||||
@@ -1376,7 +1376,7 @@ object BackupRepository {
|
||||
}
|
||||
|
||||
Log.d(TAG, "[import] Re-enabling foreign keys...")
|
||||
SignalDatabase.rawDatabase.forceForeignKeyConstraintsEnabled(true)
|
||||
SignalDatabase.writableDatabase.forceForeignKeyConstraintsEnabled(true)
|
||||
}
|
||||
|
||||
SignalDatabase.remappedRecords.clearCache()
|
||||
|
||||
@@ -108,7 +108,7 @@ class CallLogRepository(
|
||||
*/
|
||||
fun deleteAllCallLogsOnOrBeforeNow(): Single<Int> {
|
||||
return Single.fromCallable {
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
val latestCall = SignalDatabase.calls.getLatestCall() ?: return@withinTransaction
|
||||
SignalDatabase.calls.deleteNonAdHocCallEventsOnOrBefore(latestCall.timestamp)
|
||||
SignalDatabase.callLinks.deleteNonAdminCallLinksOnOrBefore(latestCall.timestamp)
|
||||
|
||||
+2
-2
@@ -178,7 +178,7 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa
|
||||
val recipient = Recipient.live(recipientId).get()
|
||||
val messageCount = 1000
|
||||
val startTime = System.currentTimeMillis() - messageCount
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
val targetThread = SignalDatabase.threads.getOrCreateThreadIdFor(recipient)
|
||||
for (i in 1..messageCount) {
|
||||
val time = startTime + i
|
||||
@@ -208,7 +208,7 @@ class InternalConversationSettingsFragment : ComposeFragment(), InternalConversa
|
||||
val recipient = Recipient.live(recipientId).get()
|
||||
val messageCount = 100
|
||||
val startTime = System.currentTimeMillis() - messageCount
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
val targetThread = SignalDatabase.threads.getOrCreateThreadIdFor(recipient)
|
||||
for (i in 1..messageCount) {
|
||||
val time = startTime + i
|
||||
|
||||
+2
-3
@@ -5,8 +5,6 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import net.zetetic.database.sqlcipher.SQLiteDatabase;
|
||||
|
||||
import org.signal.core.util.logging.Log;
|
||||
import org.signal.libsignal.protocol.IdentityKey;
|
||||
import org.signal.libsignal.protocol.SignalProtocolAddress;
|
||||
@@ -15,6 +13,7 @@ import org.thoughtcrime.securesms.crypto.ReentrantSessionLock;
|
||||
import org.thoughtcrime.securesms.crypto.storage.SignalIdentityKeyStore.SaveResult;
|
||||
import org.thoughtcrime.securesms.database.IdentityTable;
|
||||
import org.thoughtcrime.securesms.database.IdentityTable.VerifiedStatus;
|
||||
import org.thoughtcrime.securesms.database.SQLiteDatabase;
|
||||
import org.thoughtcrime.securesms.database.SignalDatabase;
|
||||
import org.thoughtcrime.securesms.database.identity.IdentityRecordList;
|
||||
import org.thoughtcrime.securesms.database.model.IdentityRecord;
|
||||
@@ -357,7 +356,7 @@ public class SignalBaseIdentityKeyStore {
|
||||
* To prevent this, writes should first acquire the DB lock before getting the cache lock to ensure we always acquire locks in the same order.
|
||||
*/
|
||||
private void withWriteLock(Runnable runnable) {
|
||||
SQLiteDatabase db = SignalDatabase.getRawDatabase();
|
||||
SQLiteDatabase db = SignalDatabase.identities().getWritableDatabase();
|
||||
db.beginTransaction();
|
||||
try {
|
||||
synchronized (this) {
|
||||
|
||||
@@ -323,7 +323,7 @@ class SearchTable(context: Context, databaseHelper: SignalDatabase) : DatabaseTa
|
||||
* Drops all tables and recreates them.
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun fullyResetTables(db: SupportSQLiteDatabase = writableDatabase.sqlCipherDatabase, useTransaction: Boolean = true) {
|
||||
fun fullyResetTables(db: SupportSQLiteDatabase = writableDatabase, useTransaction: Boolean = true) {
|
||||
if (useTransaction) {
|
||||
db.beginTransaction()
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ class BackfillDigestsForDataFileJob private constructor(
|
||||
override fun getFactoryKey(): String = KEY
|
||||
|
||||
override fun run(): Result {
|
||||
val (originalKey, decryptingStream) = SignalDatabase.rawDatabase.withinTransaction {
|
||||
val (originalKey, decryptingStream) = SignalDatabase.writableDatabase.withinTransaction {
|
||||
val attachment = SignalDatabase.attachments.getMostRecentValidAttachmentUsingDataFile(dataFile)
|
||||
if (attachment == null) {
|
||||
Log.w(TAG, "No attachments using file $dataFile exist anymore! Skipping.")
|
||||
|
||||
@@ -139,7 +139,7 @@ class BackupRestoreMediaJob private constructor(parameters: Parameters) : BaseJo
|
||||
}
|
||||
}
|
||||
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
// Mark not restorable thumbnails and attachments as failed
|
||||
SignalDatabase.attachments.setThumbnailRestoreState(notRestorable, AttachmentTable.ThumbnailRestoreState.PERMANENT_FAILURE)
|
||||
SignalDatabase.attachments.setRestoreTransferState(notRestorable, AttachmentTable.TRANSFER_PROGRESS_FAILED)
|
||||
|
||||
+1
-1
@@ -99,7 +99,7 @@ internal class DuplicateE164MigrationJob(
|
||||
}
|
||||
|
||||
Log.w(TAG, "Was not able to resolve all conflicts. We must merge the contacts together.")
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
val first = resolved.first()
|
||||
for (entry in resolved.drop(1)) {
|
||||
Log.w(TAG, "Merging ${first.id} with ${entry.id}")
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ internal class E164FormattingMigrationJob(
|
||||
val existing: Optional<RecipientId> = SignalDatabase.recipients.getByE164(formattedE164)
|
||||
if (existing.isPresent) {
|
||||
Log.w(TAG, "Merging ${existing.get()} and $id", true)
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
SignalDatabase.recipients.mergeForMigration(existing.get(), id)
|
||||
}
|
||||
Log.w(TAG, "Successfully merged ${existing.get()} and $id", true)
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ internal class StorageFixLocalUnknownMigrationJob(
|
||||
|
||||
Log.w(TAG, "Removing ${danglingLocalUnknownIds.size} dangling unknown ids")
|
||||
|
||||
SignalDatabase.rawDatabase.withinTransaction {
|
||||
SignalDatabase.writableDatabase.withinTransaction {
|
||||
SignalDatabase.unknownStorageIds.delete(danglingLocalUnknownIds)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user