From b3064ce25a9e6c7ee21b823d8491a4bfce5859ad Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 16 Dec 2020 18:00:20 +0000 Subject: [PATCH] Add event ID index on current state table (helps performance) --- syncapi/storage/postgres/current_room_state_table.go | 2 ++ syncapi/storage/sqlite3/current_room_state_table.go | 2 ++ 2 files changed, 4 insertions(+) diff --git a/syncapi/storage/postgres/current_room_state_table.go b/syncapi/storage/postgres/current_room_state_table.go index 554163e58..77e1e363f 100644 --- a/syncapi/storage/postgres/current_room_state_table.go +++ b/syncapi/storage/postgres/current_room_state_table.go @@ -58,6 +58,8 @@ CREATE TABLE IF NOT EXISTS syncapi_current_room_state ( CREATE UNIQUE INDEX IF NOT EXISTS syncapi_event_id_idx ON syncapi_current_room_state(event_id, room_id, type, sender, contains_url); -- for querying membership states of users CREATE INDEX IF NOT EXISTS syncapi_membership_idx ON syncapi_current_room_state(type, state_key, membership) WHERE membership IS NOT NULL AND membership != 'leave'; +-- for querying state by event IDs +CREATE UNIQUE INDEX IF NOT EXISTS syncapi_current_room_state_eventid_idx ON syncapi_current_room_state(event_id); ` const upsertRoomStateSQL = "" + diff --git a/syncapi/storage/sqlite3/current_room_state_table.go b/syncapi/storage/sqlite3/current_room_state_table.go index f16a66127..ac6590575 100644 --- a/syncapi/storage/sqlite3/current_room_state_table.go +++ b/syncapi/storage/sqlite3/current_room_state_table.go @@ -46,6 +46,8 @@ CREATE TABLE IF NOT EXISTS syncapi_current_room_state ( CREATE UNIQUE INDEX IF NOT EXISTS syncapi_event_id_idx ON syncapi_current_room_state(event_id, room_id, type, sender, contains_url); -- for querying membership states of users -- CREATE INDEX IF NOT EXISTS syncapi_membership_idx ON syncapi_current_room_state(type, state_key, membership) WHERE membership IS NOT NULL AND membership != 'leave'; +-- for querying state by event IDs +CREATE UNIQUE INDEX IF NOT EXISTS syncapi_current_room_state_eventid_idx ON syncapi_current_room_state(event_id); ` const upsertRoomStateSQL = "" +