From fdb65e52b78cb7f7cdf3f2b845b812d5cca6135d Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 18 Dec 2020 18:26:09 +0000 Subject: [PATCH] Query update --- syncapi/storage/postgres/output_room_events_table.go | 2 +- syncapi/storage/sqlite3/output_room_events_table.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/syncapi/storage/postgres/output_room_events_table.go b/syncapi/storage/postgres/output_room_events_table.go index ae8389a9c..b7ac1eac1 100644 --- a/syncapi/storage/postgres/output_room_events_table.go +++ b/syncapi/storage/postgres/output_room_events_table.go @@ -103,7 +103,7 @@ const updateEventJSONSQL = "" + "UPDATE syncapi_output_room_events SET headered_event_json=$1 WHERE event_id=$2" const selectCountStateChangesInRangeSQL = "" + - "SELECT COUNT(*), MIN(id), MAX(id) FROM syncapi_output_room_events" + + "SELECT COUNT(id), COALESCE(MIN(id), 0) AS min, COALESCE(MAX(id), 0) AS max FROM syncapi_output_room_events" + " WHERE (id > $1 AND id <= $2) AND (cardinality (add_state_ids) > 0 OR cardinality (remove_state_ids) > 0)" // In order for us to apply the state updates correctly, rows need to be ordered in the order they were received (id). diff --git a/syncapi/storage/sqlite3/output_room_events_table.go b/syncapi/storage/sqlite3/output_room_events_table.go index ebe347bbc..8da43b847 100644 --- a/syncapi/storage/sqlite3/output_room_events_table.go +++ b/syncapi/storage/sqlite3/output_room_events_table.go @@ -92,7 +92,7 @@ const updateEventJSONSQL = "" + */ const selectCountStateChangesInRangeSQL = "" + - "SELECT COUNT(*), coalesce(MIN(id), 0) AS min, coalesce(MAX(id), 0) AS max FROM syncapi_output_room_events" + + "SELECT COUNT(*), MIN(id), MAX(id) AS max FROM syncapi_output_room_events" + " WHERE (id > $1 AND id <= $2) AND ((add_state_ids IS NULL OR add_state_ids = '') OR (remove_state_ids IS NULL OR remove_state_ids = ''))" const selectStateInRangeSQL = "" +