mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-22 19:51:39 +00:00
selectRecentEvents: reverse events in SQL query (#386)
Signed-off-by: Thibaut CHARLES cromfr@gmail.com
This commit is contained in:
parent
8a3f9b0561
commit
27c335438f
@ -65,7 +65,7 @@ const selectEventsSQL = "" +
|
|||||||
const selectRecentEventsSQL = "" +
|
const selectRecentEventsSQL = "" +
|
||||||
"SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" +
|
"SELECT id, event_json, device_id, transaction_id FROM syncapi_output_room_events" +
|
||||||
" WHERE room_id = $1 AND id > $2 AND id <= $3" +
|
" WHERE room_id = $1 AND id > $2 AND id <= $3" +
|
||||||
" ORDER BY id DESC LIMIT $4"
|
" ORDER BY id ASC LIMIT $4"
|
||||||
|
|
||||||
const selectMaxEventIDSQL = "" +
|
const selectMaxEventIDSQL = "" +
|
||||||
"SELECT MAX(id) FROM syncapi_output_room_events"
|
"SELECT MAX(id) FROM syncapi_output_room_events"
|
||||||
@ -234,9 +234,7 @@ func (s *outputRoomEventsStatements) selectRecentEvents(
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// reverse the order because [0] is the newest event due to the ORDER BY in SQL-land. The reverse order makes [0] the oldest event,
|
return events, nil
|
||||||
// which is correct for /sync responses.
|
|
||||||
return reverseEvents(events), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events returns the events for the given event IDs. Returns an error if any one of the event IDs given are missing
|
// Events returns the events for the given event IDs. Returns an error if any one of the event IDs given are missing
|
||||||
@ -287,10 +285,3 @@ func rowsToStreamEvents(rows *sql.Rows) ([]streamEvent, error) {
|
|||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func reverseEvents(input []streamEvent) (output []streamEvent) {
|
|
||||||
for i := len(input) - 1; i >= 0; i-- {
|
|
||||||
output = append(output, input[i])
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user