aboutsummaryrefslogtreecommitdiff
path: root/syncapi/storage
diff options
context:
space:
mode:
authorNeil Alexander <neilalexander@users.noreply.github.com>2020-01-24 11:40:27 +0000
committerGitHub <noreply@github.com>2020-01-24 11:40:27 +0000
commitdece31f41ee096712a4415f09f4f9725068efe9d (patch)
treee8970bea861edc114227d09f7baa3282bc4c5fa0 /syncapi/storage
parent49f760a30b6496c8b3e1ceaf98dccc4376f6605d (diff)
Some fixes for #847 (#850)
* Fix a couple of cases where backfilling events we already had causes panics, hopefully fix ordering of events, update GMSL dependency for backfill URL fixes * Remove commented out lines from output_room_events_table schema
Diffstat (limited to 'syncapi/storage')
-rw-r--r--syncapi/storage/postgres/backward_extremities_table.go3
-rw-r--r--syncapi/storage/postgres/output_room_events_table.go8
2 files changed, 6 insertions, 5 deletions
diff --git a/syncapi/storage/postgres/backward_extremities_table.go b/syncapi/storage/postgres/backward_extremities_table.go
index 476d26fa..1489f7f9 100644
--- a/syncapi/storage/postgres/backward_extremities_table.go
+++ b/syncapi/storage/postgres/backward_extremities_table.go
@@ -33,7 +33,8 @@ CREATE TABLE IF NOT EXISTS syncapi_backward_extremities (
const insertBackwardExtremitySQL = "" +
"INSERT INTO syncapi_backward_extremities (room_id, event_id)" +
- " VALUES ($1, $2)"
+ " VALUES ($1, $2)" +
+ " ON CONFLICT DO NOTHING"
const selectBackwardExtremitiesForRoomSQL = "" +
"SELECT event_id FROM syncapi_backward_extremities WHERE room_id = $1"
diff --git a/syncapi/storage/postgres/output_room_events_table.go b/syncapi/storage/postgres/output_room_events_table.go
index be302d73..6d213a57 100644
--- a/syncapi/storage/postgres/output_room_events_table.go
+++ b/syncapi/storage/postgres/output_room_events_table.go
@@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS syncapi_output_room_events (
-- This isn't a problem for us since we just want to order by this field.
id BIGINT PRIMARY KEY DEFAULT nextval('syncapi_stream_id'),
-- The event ID for the event
- event_id TEXT NOT NULL,
+ event_id TEXT NOT NULL CONSTRAINT syncapi_event_id_idx UNIQUE,
-- The 'room_id' key for the event.
room_id TEXT NOT NULL,
-- The JSON for the event. Stored as TEXT because this should be valid UTF-8.
@@ -67,14 +67,14 @@ CREATE TABLE IF NOT EXISTS syncapi_output_room_events (
-- were emitted.
exclude_from_sync BOOL DEFAULT FALSE
);
--- for event selection
-CREATE UNIQUE INDEX IF NOT EXISTS syncapi_event_id_idx ON syncapi_output_room_events(event_id);
`
const insertEventSQL = "" +
"INSERT INTO syncapi_output_room_events (" +
"room_id, event_id, event_json, type, sender, contains_url, add_state_ids, remove_state_ids, session_id, transaction_id, exclude_from_sync" +
- ") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING id"
+ ") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) " +
+ "ON CONFLICT ON CONSTRAINT syncapi_event_id_idx DO UPDATE SET exclude_from_sync = $11 " +
+ "RETURNING id"
const selectEventsSQL = "" +
"SELECT id, event_json, session_id, exclude_from_sync, transaction_id FROM syncapi_output_room_events WHERE event_id = ANY($1)"