From 6cab62246816baf1fdd026744727cba9a7b21c28 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 2 Jan 2020 14:51:21 +0000 Subject: [PATCH] Amend syncapi SQL queries to return missing columns (#840) * This commit updates a couple of the syncapi SQL queries to return additional columns that are required/expected by rowsToStreamEvents in output_room_events_table.go. It's not exactly clear to me yet what transaction_id and session_id do, but these being added n #367 results in state events breaking the /sync endpoint. This is a temporary fix. We need to come up with a better solution. * gomatrix to gomatrixserverlib on some weird line change * Tweaks from @babolivier review comments --- syncapi/storage/current_room_state_table.go | 7 ++++++- syncapi/storage/output_room_events_table.go | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/syncapi/storage/current_room_state_table.go b/syncapi/storage/current_room_state_table.go index 88e7a76c3..1ab70879a 100644 --- a/syncapi/storage/current_room_state_table.go +++ b/syncapi/storage/current_room_state_table.go @@ -84,7 +84,12 @@ const selectStateEventSQL = "" + "SELECT event_json FROM syncapi_current_room_state WHERE room_id = $1 AND type = $2 AND state_key = $3" const selectEventsWithEventIDsSQL = "" + - "SELECT added_at, event_json FROM syncapi_current_room_state WHERE event_id = ANY($1)" + // TODO: The session_id and transaction_id blanks are here because otherwise + // the rowsToStreamEvents expects there to be exactly four columns. We need to + // figure out if these really need to be in the DB, and if so, we need a + // better permanent fix for this. - neilalexander, 2 Jan 2020 + "SELECT added_at, event_json, 0 AS session_id, '' AS transaction_id" + + " FROM syncapi_current_room_state WHERE event_id = ANY($1)" type currentRoomStateStatements struct { upsertRoomStateStmt *sql.Stmt diff --git a/syncapi/storage/output_room_events_table.go b/syncapi/storage/output_room_events_table.go index 2df2a96a1..e1803a17d 100644 --- a/syncapi/storage/output_room_events_table.go +++ b/syncapi/storage/output_room_events_table.go @@ -67,7 +67,7 @@ const insertEventSQL = "" + ") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10) RETURNING id" const selectEventsSQL = "" + - "SELECT id, event_json FROM syncapi_output_room_events WHERE event_id = ANY($1)" + "SELECT id, event_json, session_id, transaction_id FROM syncapi_output_room_events WHERE event_id = ANY($1)" const selectRecentEventsSQL = "" + "SELECT id, event_json, session_id, transaction_id FROM syncapi_output_room_events" +