From ba7a54254893ee4199b93ee28346bfde47310deb Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 17 Mar 2022 12:13:37 +0000 Subject: [PATCH] tweaks --- syncapi/routing/messages.go | 14 ++++++++++---- .../postgres/output_room_events_topology_table.go | 4 ++-- .../sqlite3/output_room_events_topology_table.go | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/syncapi/routing/messages.go b/syncapi/routing/messages.go index c4224bdd2..36ba3a3e6 100644 --- a/syncapi/routing/messages.go +++ b/syncapi/routing/messages.go @@ -48,10 +48,11 @@ type messagesReq struct { } type messagesResp struct { - Start string `json:"start"` - End string `json:"end"` - Chunk []gomatrixserverlib.ClientEvent `json:"chunk"` - State []gomatrixserverlib.ClientEvent `json:"state"` + Start string `json:"start"` + StartStream string `json:"start_stream,omitempty"` // NOTSPEC: used by Cerulean, so clients can hit /messages then immediately /sync with a latest sync token + End string `json:"end"` + Chunk []gomatrixserverlib.ClientEvent `json:"chunk"` + State []gomatrixserverlib.ClientEvent `json:"state"` } // OnIncomingMessagesRequest implements the /messages endpoint from the @@ -89,6 +90,7 @@ func OnIncomingMessagesRequest( // Extract parameters from the request's URL. // Pagination tokens. + var fromStream *types.StreamingToken fromQuery := req.URL.Query().Get("from") toQuery := req.URL.Query().Get("to") emptyFromSupplied := fromQuery == "" @@ -120,6 +122,7 @@ func OnIncomingMessagesRequest( JSON: jsonerror.InvalidArgumentValue("Invalid from parameter: " + err.Error()), } } else { + fromStream = &streamToken from, err = db.StreamToTopologicalPosition(req.Context(), roomID, streamToken.PDUPosition, backwardOrdering) if err != nil { logrus.WithError(err).Errorf("Failed to get topological position for streaming token %v", streamToken) @@ -226,6 +229,9 @@ func OnIncomingMessagesRequest( End: end.String(), State: state, } + if fromStream != nil { + res.StartStream = fromStream.String() + } // Respond with the events. return util.JSONResponse{ diff --git a/syncapi/storage/postgres/output_room_events_topology_table.go b/syncapi/storage/postgres/output_room_events_topology_table.go index fbeb90e64..cf523d529 100644 --- a/syncapi/storage/postgres/output_room_events_topology_table.go +++ b/syncapi/storage/postgres/output_room_events_topology_table.go @@ -50,14 +50,14 @@ const insertEventInTopologySQL = "" + const selectEventIDsInRangeASCSQL = "" + "SELECT event_id FROM syncapi_output_room_events_topology" + " WHERE room_id = $1 AND (" + - "(topological_position > $2 AND topological_position <= $3) OR" + + "(topological_position > $2 AND topological_position < $3) OR" + "(topological_position = $4 AND stream_position <= $5)" + ") ORDER BY topological_position ASC, stream_position ASC LIMIT $6" const selectEventIDsInRangeDESCSQL = "" + "SELECT event_id FROM syncapi_output_room_events_topology" + " WHERE room_id = $1 AND (" + - "(topological_position >= $2 AND topological_position < $3) OR" + + "(topological_position > $2 AND topological_position < $3) OR" + "(topological_position = $4 AND stream_position <= $5)" + ") ORDER BY topological_position DESC, stream_position DESC LIMIT $6" diff --git a/syncapi/storage/sqlite3/output_room_events_topology_table.go b/syncapi/storage/sqlite3/output_room_events_topology_table.go index c4673786d..08601efba 100644 --- a/syncapi/storage/sqlite3/output_room_events_topology_table.go +++ b/syncapi/storage/sqlite3/output_room_events_topology_table.go @@ -46,14 +46,14 @@ const insertEventInTopologySQL = "" + const selectEventIDsInRangeASCSQL = "" + "SELECT event_id FROM syncapi_output_room_events_topology" + " WHERE room_id = $1 AND (" + - "(topological_position > $2 AND topological_position <= $3) OR" + + "(topological_position > $2 AND topological_position < $3) OR" + "(topological_position = $4 AND stream_position <= $5)" + ") ORDER BY topological_position ASC, stream_position ASC LIMIT $6" const selectEventIDsInRangeDESCSQL = "" + "SELECT event_id FROM syncapi_output_room_events_topology" + " WHERE room_id = $1 AND (" + - "(topological_position >= $2 AND topological_position < $3) OR" + + "(topological_position > $2 AND topological_position < $3) OR" + "(topological_position = $4 AND stream_position <= $5)" + ") ORDER BY topological_position DESC, stream_position DESC LIMIT $6"