From 59889d00130819eeab1d65286726fb7d2d9a1d33 Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Tue, 4 Jun 2019 14:05:42 +1000 Subject: [PATCH] Add missing index --- src/org/thoughtcrime/securesms/crypto/PreKeyUtil.java | 3 --- src/org/thoughtcrime/securesms/loki/LokiAPIDatabase.kt | 8 +++----- .../securesms/loki/LokiContactPreKeyDatabase.kt | 5 +++-- .../{LokiDatabaseUtils.kt => LokiDatabaseUtilities.kt} | 0 4 files changed, 6 insertions(+), 10 deletions(-) rename src/org/thoughtcrime/securesms/loki/{LokiDatabaseUtils.kt => LokiDatabaseUtilities.kt} (100%) diff --git a/src/org/thoughtcrime/securesms/crypto/PreKeyUtil.java b/src/org/thoughtcrime/securesms/crypto/PreKeyUtil.java index 400a96147d..092d0ecc52 100644 --- a/src/org/thoughtcrime/securesms/crypto/PreKeyUtil.java +++ b/src/org/thoughtcrime/securesms/crypto/PreKeyUtil.java @@ -91,7 +91,6 @@ public class PreKeyUtil { } // region - Loki - public synchronized static List generatePreKeys(Context context, int amount) { PreKeyStore preKeyStore = new TextSecurePreKeyStore(context); List records = new LinkedList<>(); @@ -122,7 +121,5 @@ public class PreKeyUtil { PreKeyStore preKeyStore = new TextSecurePreKeyStore(context); return preKeyStore.loadPreKey(preKeyId); } - // endregion - } diff --git a/src/org/thoughtcrime/securesms/loki/LokiAPIDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiAPIDatabase.kt index 37cafa6b4b..6d6087c3cc 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiAPIDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiAPIDatabase.kt @@ -2,7 +2,6 @@ package org.thoughtcrime.securesms.loki import android.content.ContentValues import android.content.Context -import android.database.Cursor import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.whispersystems.signalservice.loki.api.LokiAPIDatabaseProtocol @@ -15,17 +14,17 @@ class LokiAPIDatabase(private val userPublicKey: String, context: Context, helpe private val swarmCache = "loki_api_swarm_cache" private val hexEncodedPublicKey = "hex_encoded_public_key" private val swarm = "swarm" - @JvmStatic val createSwarmCacheTableCommand = "CREATE TABLE $swarmCache ($hexEncodedPublicKey TEXT, $swarm TEXT);" + @JvmStatic val createSwarmCacheTableCommand = "CREATE TABLE $swarmCache ($hexEncodedPublicKey TEXT PRIMARY KEY, $swarm TEXT);" // Last message hash value cache private val lastMessageHashValueCache = "loki_api_last_message_hash_value_cache" private val target = "target" private val lastMessageHashValue = "last_message_hash_value" - @JvmStatic val createLastMessageHashValueTableCommand = "CREATE TABLE $lastMessageHashValueCache ($target TEXT, $lastMessageHashValue TEXT);" + @JvmStatic val createLastMessageHashValueTableCommand = "CREATE TABLE $lastMessageHashValueCache ($target TEXT PRIMARY KEY, $lastMessageHashValue TEXT);" // Received message hash values cache private val receivedMessageHashValuesCache = "loki_api_received_message_hash_values_cache" private val userID = "user_id" private val receivedMessageHashValues = "received_message_hash_values" - @JvmStatic val createReceivedMessageHashValuesTableCommand = "CREATE TABLE $receivedMessageHashValuesCache ($userID TEXT, $receivedMessageHashValues TEXT);" + @JvmStatic val createReceivedMessageHashValuesTableCommand = "CREATE TABLE $receivedMessageHashValuesCache ($userID TEXT PRIMARY KEY, $receivedMessageHashValues TEXT);" } override fun getSwarmCache(hexEncodedPublicKey: String): List? { @@ -75,7 +74,6 @@ class LokiAPIDatabase(private val userPublicKey: String, context: Context, helpe } // region Convenience - private inline fun wrap(x: T): Array { return Array(1) { x } } diff --git a/src/org/thoughtcrime/securesms/loki/LokiContactPreKeyDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiContactPreKeyDatabase.kt index 028cc0ee65..37985f340d 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiContactPreKeyDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiContactPreKeyDatabase.kt @@ -9,13 +9,14 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.whispersystems.libsignal.state.PreKeyRecord /** - * A database for associating a `PreKeyRecord` id to a contact public key. + * A database for associating pre key records to contact public keys. */ class LokiContactPreKeyDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) { + companion object { private val tableName = "loki_contact_pre_key_database" - private val pubKey = "pub_key" private val preKeyId = "pre_key_id" + private val pubKey = "pub_key" @JvmStatic val createTableCommand = "CREATE TABLE $tableName ($preKeyId INTEGER PRIMARY KEY, $pubKey TEXT);" diff --git a/src/org/thoughtcrime/securesms/loki/LokiDatabaseUtils.kt b/src/org/thoughtcrime/securesms/loki/LokiDatabaseUtilities.kt similarity index 100% rename from src/org/thoughtcrime/securesms/loki/LokiDatabaseUtils.kt rename to src/org/thoughtcrime/securesms/loki/LokiDatabaseUtilities.kt