Review comments

This commit is contained in:
Kegan Dougal 2017-04-05 09:36:44 +01:00
parent 0b4e2817c3
commit 9520c718cc
3 changed files with 10 additions and 0 deletions

View file

@ -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 = "" +

View file

@ -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 = "" +

View file

@ -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.