From 4b970e0ea7e691bcc921cb6bdb2e553bcbcc569e Mon Sep 17 00:00:00 2001 From: Brad Murray Date: Tue, 26 Nov 2024 15:29:18 -0500 Subject: [PATCH] crypto/sqlstore: add index to crypto_olm_sessions table to speed up lookups by sender_key (#323) Co-authored-by: Tulir Asokan --- crypto/sql_store_upgrade/00-latest-revision.sql | 3 ++- crypto/sql_store_upgrade/16-crypto-olm-sessions-index.sql | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) create mode 100644 crypto/sql_store_upgrade/16-crypto-olm-sessions-index.sql diff --git a/crypto/sql_store_upgrade/00-latest-revision.sql b/crypto/sql_store_upgrade/00-latest-revision.sql index 7e039af5..7cd3331c 100644 --- a/crypto/sql_store_upgrade/00-latest-revision.sql +++ b/crypto/sql_store_upgrade/00-latest-revision.sql @@ -1,4 +1,4 @@ --- v0 -> v15: Latest revision +-- v0 -> v16 (compatible with v15+): Latest revision CREATE TABLE IF NOT EXISTS crypto_account ( account_id TEXT PRIMARY KEY, device_id TEXT NOT NULL, @@ -43,6 +43,7 @@ CREATE TABLE IF NOT EXISTS crypto_olm_session ( last_encrypted timestamp NOT NULL, PRIMARY KEY (account_id, session_id) ); +CREATE INDEX crypto_olm_session_sender_key_idx ON crypto_olm_session (account_id, sender_key); CREATE TABLE IF NOT EXISTS crypto_megolm_inbound_session ( account_id TEXT, diff --git a/crypto/sql_store_upgrade/16-crypto-olm-sessions-index.sql b/crypto/sql_store_upgrade/16-crypto-olm-sessions-index.sql new file mode 100644 index 00000000..f0c3a0c5 --- /dev/null +++ b/crypto/sql_store_upgrade/16-crypto-olm-sessions-index.sql @@ -0,0 +1,2 @@ +-- v16 (compatible with v15+): Add index to crypto_olm_sessions to speedup lookups by sender_key +CREATE INDEX crypto_olm_session_sender_key_idx ON crypto_olm_session (account_id, sender_key);