mirror of
https://github.com/matrix-org/dendrite.git
synced 2026-01-03 12:13:09 -06:00
Use To in worst case
This commit is contained in:
parent
e28760907d
commit
3df6523a32
|
|
@ -220,24 +220,19 @@ func (p *PDUStreamProvider) addRoomDeltaToResponse(
|
||||||
return r.From, err
|
return r.From, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we didn't return any events at all then don't bother advancing the stream position.
|
|
||||||
if len(recentEvents) == 0 && len(delta.StateEvents) == 0 {
|
|
||||||
return r.From, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sort the events so that we can pick out the latest events from both sections.
|
// Sort the events so that we can pick out the latest events from both sections.
|
||||||
recentEvents = gomatrixserverlib.HeaderedReverseTopologicalOrdering(recentEvents, gomatrixserverlib.TopologicalOrderByPrevEvents)
|
recentEvents = gomatrixserverlib.HeaderedReverseTopologicalOrdering(recentEvents, gomatrixserverlib.TopologicalOrderByPrevEvents)
|
||||||
delta.StateEvents = gomatrixserverlib.HeaderedReverseTopologicalOrdering(delta.StateEvents, gomatrixserverlib.TopologicalOrderByAuthEvents)
|
delta.StateEvents = gomatrixserverlib.HeaderedReverseTopologicalOrdering(delta.StateEvents, gomatrixserverlib.TopologicalOrderByAuthEvents)
|
||||||
|
|
||||||
// Work out what the highest stream position is for all of the events in this
|
// Work out what the highest stream position is for all of the events in this
|
||||||
// room that were returned.
|
// room that were returned.
|
||||||
latestPosition := r.From
|
latestPosition := r.To
|
||||||
updateLatestPosition := func(mostRecentEventID string) {
|
updateLatestPosition := func(mostRecentEventID string) {
|
||||||
if _, pos, err := p.DB.PositionInTopology(ctx, mostRecentEventID); err == nil {
|
if _, pos, err := p.DB.PositionInTopology(ctx, mostRecentEventID); err == nil {
|
||||||
switch {
|
switch {
|
||||||
case r.Backwards && pos < latestPosition:
|
case r.Backwards && pos > latestPosition:
|
||||||
fallthrough
|
fallthrough
|
||||||
case !r.Backwards && pos > latestPosition:
|
case !r.Backwards && pos < latestPosition:
|
||||||
latestPosition = pos
|
latestPosition = pos
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue