Optimize /sync a bit
This commit is contained in:
parent
e449d174cc
commit
c915689d20
|
@ -137,7 +137,7 @@ const updateEventJSONSQL = "" +
|
|||
const selectStateInRangeFilteredSQL = "" +
|
||||
"SELECT event_id, id, headered_event_json, exclude_from_sync, add_state_ids, remove_state_ids, history_visibility" +
|
||||
" FROM syncapi_output_room_events" +
|
||||
" WHERE (id > $1 AND id <= $2) AND (add_state_ids IS NOT NULL OR remove_state_ids IS NOT NULL)" +
|
||||
" WHERE (id > $1 AND id <= $2) AND (cardinality(add_state_ids) > 0 OR cardinality(remove_state_ids) > 0)" +
|
||||
" AND room_id = ANY($3)" +
|
||||
" AND ( $4::text[] IS NULL OR sender = ANY($4) )" +
|
||||
" AND ( $5::text[] IS NULL OR NOT(sender = ANY($5)) )" +
|
||||
|
@ -150,7 +150,7 @@ const selectStateInRangeFilteredSQL = "" +
|
|||
const selectStateInRangeSQL = "" +
|
||||
"SELECT event_id, id, headered_event_json, exclude_from_sync, add_state_ids, remove_state_ids, history_visibility" +
|
||||
" FROM syncapi_output_room_events" +
|
||||
" WHERE (id > $1 AND id <= $2) AND (add_state_ids IS NOT NULL OR remove_state_ids IS NOT NULL)" +
|
||||
" WHERE (id > $1 AND id <= $2) AND (cardinality(add_state_ids) > 0 OR cardinality(remove_state_ids) > 0)" +
|
||||
" AND room_id = ANY($3)" +
|
||||
" ORDER BY id ASC"
|
||||
|
||||
|
|
|
@ -329,7 +329,13 @@ func (d *DatabaseTransaction) GetStateDeltas(
|
|||
}
|
||||
|
||||
// get all the state events ever (i.e. for all available rooms) between these two positions
|
||||
stateNeededFiltered, eventMapFiltered, err := d.OutputEvents.SelectStateInRange(ctx, d.txn, r, stateFilter, allRoomIDs)
|
||||
stateNeededFiltered := stateNeeded
|
||||
eventMapFiltered := eventMap
|
||||
// avoid hitting the database if the result would be the same as above
|
||||
if stateFilter != nil {
|
||||
stateNeededFiltered, eventMapFiltered, err = d.OutputEvents.SelectStateInRange(ctx, d.txn, r, stateFilter, allRoomIDs)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil, nil
|
||||
|
|
Loading…
Reference in a new issue