From 9520c718cc925967d9048dcd4e70c404492b12f1 Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Wed, 5 Apr 2017 09:36:44 +0100 Subject: [PATCH] Review comments --- .../dendrite/clientapi/storage/current_room_state_table.go | 2 ++ .../dendrite/clientapi/storage/output_room_events_table.go | 2 ++ .../matrix-org/dendrite/clientapi/storage/syncserver.go | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/src/github.com/matrix-org/dendrite/clientapi/storage/current_room_state_table.go b/src/github.com/matrix-org/dendrite/clientapi/storage/current_room_state_table.go index 229306ab4..bff60972f 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/storage/current_room_state_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/storage/current_room_state_table.go @@ -27,6 +27,8 @@ CREATE TABLE IF NOT EXISTS current_room_state ( -- Clobber based on 3-uple of room_id, type and state_key CONSTRAINT room_state_unique UNIQUE (room_id, type, state_key) ); +-- for event deletion +CREATE UNIQUE INDEX IF NOT EXISTS event_id_idx ON current_room_state(event_id); ` const upsertRoomStateSQL = "" + diff --git a/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go b/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go index 26cf1cdb8..a31759c3a 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/storage/output_room_events_table.go @@ -26,6 +26,8 @@ CREATE TABLE IF NOT EXISTS output_room_events ( add_state_ids TEXT[], remove_state_ids TEXT[] ); +-- for event selection +CREATE UNIQUE INDEX IF NOT EXISTS event_id_idx ON output_room_events(event_id); ` const insertEventSQL = "" + diff --git a/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go b/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go index 6a85f703a..39df640b1 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go +++ b/src/github.com/matrix-org/dendrite/clientapi/storage/syncserver.go @@ -45,6 +45,12 @@ func (d *SyncServerDatabase) WriteEvent(ev *gomatrixserverlib.Event, addStateEve if err := d.events.InsertEvent(txn, ev, addStateEventIDs, removeStateEventIDs); err != nil { return err } + + if len(addStateEventIDs) == 0 && len(removeStateEventIDs) == 0 { + // Nothing to do, the event may have just been a message event. + return nil + } + // Update the current room state based on the added/removed state event IDs. // In the common case there is a single added event ID which is the state event itself, assuming `ev` is a state event. // However, conflict resolution may result in there being different events being added, or even some removed.