mirror of
https://github.com/hoernschen/dendrite.git
synced 2024-12-27 23:48:27 +00:00
Limit the number of events returned by the database query when using topological tokens
This commit is contained in:
parent
b028a31f7f
commit
f600d520de
2 changed files with 5 additions and 5 deletions
|
@ -44,12 +44,12 @@ const insertEventInTopologySQL = "" +
|
||||||
const selectEventIDsInRangeASCSQL = "" +
|
const selectEventIDsInRangeASCSQL = "" +
|
||||||
"SELECT event_id FROM syncapi_output_room_events_topology" +
|
"SELECT event_id FROM syncapi_output_room_events_topology" +
|
||||||
" WHERE room_id = $1 AND topological_position > $2 AND topological_position <= $3" +
|
" WHERE room_id = $1 AND topological_position > $2 AND topological_position <= $3" +
|
||||||
" ORDER BY topological_position ASC"
|
" ORDER BY topological_position ASC LIMIT $4"
|
||||||
|
|
||||||
const selectEventIDsInRangeDESCSQL = "" +
|
const selectEventIDsInRangeDESCSQL = "" +
|
||||||
"SELECT event_id FROM syncapi_output_room_events_topology" +
|
"SELECT event_id FROM syncapi_output_room_events_topology" +
|
||||||
" WHERE room_id = $1 AND topological_position > $2 AND topological_position <= $3" +
|
" WHERE room_id = $1 AND topological_position > $2 AND topological_position <= $3" +
|
||||||
" ORDER BY topological_position DESC"
|
" ORDER BY topological_position DESC LIMIT $4"
|
||||||
|
|
||||||
const selectPositionInTopologySQL = "" +
|
const selectPositionInTopologySQL = "" +
|
||||||
"SELECT topological_position FROM syncapi_output_room_events_topology" +
|
"SELECT topological_position FROM syncapi_output_room_events_topology" +
|
||||||
|
@ -114,7 +114,7 @@ func (s *outputRoomEventsTopologyStatements) insertEventInTopology(
|
||||||
// Returns an empty slice if no events match the given range.
|
// Returns an empty slice if no events match the given range.
|
||||||
func (s *outputRoomEventsTopologyStatements) selectEventIDsInRange(
|
func (s *outputRoomEventsTopologyStatements) selectEventIDsInRange(
|
||||||
ctx context.Context, roomID string, fromPos, toPos types.StreamPosition,
|
ctx context.Context, roomID string, fromPos, toPos types.StreamPosition,
|
||||||
chronologicalOrder bool,
|
limit int, chronologicalOrder bool,
|
||||||
) (eventIDs []string, err error) {
|
) (eventIDs []string, err error) {
|
||||||
// Decide on the selection's order according to whether chronological order
|
// Decide on the selection's order according to whether chronological order
|
||||||
// is requested or not.
|
// is requested or not.
|
||||||
|
@ -126,7 +126,7 @@ func (s *outputRoomEventsTopologyStatements) selectEventIDsInRange(
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the event IDs.
|
// Query the event IDs.
|
||||||
rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos)
|
rows, err := stmt.QueryContext(ctx, roomID, fromPos, toPos, limit)
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
// If no event matched the request, return an empty slice.
|
// If no event matched the request, return an empty slice.
|
||||||
return []string{}, nil
|
return []string{}, nil
|
||||||
|
|
|
@ -227,7 +227,7 @@ func (d *SyncServerDatabase) GetEventsInRange(
|
||||||
// Select the event IDs from the defined range.
|
// Select the event IDs from the defined range.
|
||||||
var eIDs []string
|
var eIDs []string
|
||||||
eIDs, err = d.topology.selectEventIDsInRange(
|
eIDs, err = d.topology.selectEventIDsInRange(
|
||||||
ctx, roomID, backwardLimit, forwardLimit, !backwardOrdering,
|
ctx, roomID, backwardLimit, forwardLimit, limit, !backwardOrdering,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue