More sync fixes (#854)

* Further sync tweaks

* Remove unnecessary blank line

* getBackwardTopologyPos always returns a usable value

* Revert order fixing
This commit is contained in:
Neil Alexander 2020-01-25 14:23:16 +00:00 committed by GitHub
parent 2cb7c91c5d
commit 054f5383c4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 14 deletions

View file

@ -40,7 +40,7 @@ CREATE UNIQUE INDEX IF NOT EXISTS syncapi_event_topological_position_idx ON sync
const insertEventInTopologySQL = "" + const insertEventInTopologySQL = "" +
"INSERT INTO syncapi_output_room_events_topology (event_id, topological_position, room_id)" + "INSERT INTO syncapi_output_room_events_topology (event_id, topological_position, room_id)" +
" VALUES ($1, $2, $3)" + " VALUES ($1, $2, $3)" +
" ON CONFLICT DO NOTHING" " ON CONFLICT (topological_position, room_id) DO UPDATE SET event_id = $1"
const selectEventIDsInRangeASCSQL = "" + const selectEventIDsInRangeASCSQL = "" +
"SELECT event_id FROM syncapi_output_room_events_topology" + "SELECT event_id FROM syncapi_output_room_events_topology" +

View file

@ -602,7 +602,6 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
recentStreamEvents, err = d.events.selectRecentEvents( recentStreamEvents, err = d.events.selectRecentEvents(
ctx, txn, roomID, types.StreamPosition(0), toPos.PDUPosition, ctx, txn, roomID, types.StreamPosition(0), toPos.PDUPosition,
numRecentEventsPerRoom, true, true, numRecentEventsPerRoom, true, true,
//ctx, txn, roomID, 0, toPos.PDUPosition, numRecentEventsPerRoom,
) )
if err != nil { if err != nil {
return return
@ -618,7 +617,7 @@ func (d *SyncServerDatasource) getResponseWithPDUsForCompleteSync(
if backwardTopologyPos-1 <= 0 { if backwardTopologyPos-1 <= 0 {
backwardTopologyPos = types.StreamPosition(1) backwardTopologyPos = types.StreamPosition(1)
} else { } else {
backwardTopologyPos = backwardTopologyPos - 1 backwardTopologyPos--
} }
// We don't include a device here as we don't need to send down // We don't include a device here as we don't need to send down
@ -767,12 +766,9 @@ func (d *SyncServerDatasource) addInvitesToResponse(
func (d *SyncServerDatasource) getBackwardTopologyPos( func (d *SyncServerDatasource) getBackwardTopologyPos(
ctx context.Context, ctx context.Context,
events []types.StreamEvent, events []types.StreamEvent,
) (pos types.StreamPosition, err error) { ) (pos types.StreamPosition) {
if len(events) > 0 { if len(events) > 0 {
pos, err = d.topology.selectPositionInTopology(ctx, events[0].EventID()) pos, _ = d.topology.selectPositionInTopology(ctx, events[0].EventID())
if err != nil {
return
}
} }
if pos-1 <= 0 { if pos-1 <= 0 {
pos = types.StreamPosition(1) pos = types.StreamPosition(1)
@ -811,12 +807,7 @@ func (d *SyncServerDatasource) addRoomDeltaToResponse(
} }
recentEvents := d.StreamEventsToEvents(device, recentStreamEvents) recentEvents := d.StreamEventsToEvents(device, recentStreamEvents)
delta.stateEvents = removeDuplicates(delta.stateEvents, recentEvents) // roll back delta.stateEvents = removeDuplicates(delta.stateEvents, recentEvents) // roll back
backwardTopologyPos := d.getBackwardTopologyPos(ctx, recentStreamEvents)
var backwardTopologyPos types.StreamPosition
backwardTopologyPos, err = d.getBackwardTopologyPos(ctx, recentStreamEvents)
if err != nil {
return err
}
switch delta.membership { switch delta.membership {
case gomatrixserverlib.Join: case gomatrixserverlib.Join: