Make "Outbound federation can backfill events" pass sytest (#1049)
- Use a backfill limit of 100 regardless of what was asked. - Special case the create event for `StateIDsBeforeEvent` - Trim to the limit in `syncapi`
This commit is contained in:
parent
5faecdac82
commit
260e69d138
4 changed files with 21 additions and 2 deletions
|
@ -535,9 +535,14 @@ func (r *RoomserverInternalAPI) backfillViaFederation(ctx context.Context, req *
|
||||||
return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err)
|
return fmt.Errorf("backfillViaFederation: unknown room version for room %s : %w", req.RoomID, err)
|
||||||
}
|
}
|
||||||
requester := newBackfillRequester(r.DB, r.FedClient, r.ServerName)
|
requester := newBackfillRequester(r.DB, r.FedClient, r.ServerName)
|
||||||
|
// Request 100 items regardless of what the query asks for.
|
||||||
|
// We don't want to go much higher than this.
|
||||||
|
// We can't honour exactly the limit as some sytests rely on requesting more for tests to pass
|
||||||
|
// (so we don't need to hit /state_ids which the test has no listener for)
|
||||||
|
// Specifically the test "Outbound federation can backfill events"
|
||||||
events, err := gomatrixserverlib.RequestBackfill(
|
events, err := gomatrixserverlib.RequestBackfill(
|
||||||
ctx, requester,
|
ctx, requester,
|
||||||
r.KeyRing, req.RoomID, roomVer, req.EarliestEventsIDs, req.Limit)
|
r.KeyRing, req.RoomID, roomVer, req.EarliestEventsIDs, 100)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/matrix-org/dendrite/roomserver/storage"
|
"github.com/matrix-org/dendrite/roomserver/storage"
|
||||||
"github.com/matrix-org/dendrite/roomserver/types"
|
"github.com/matrix-org/dendrite/roomserver/types"
|
||||||
"github.com/matrix-org/gomatrixserverlib"
|
"github.com/matrix-org/gomatrixserverlib"
|
||||||
|
"github.com/matrix-org/util"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -37,6 +38,11 @@ func (b *backfillRequester) StateIDsBeforeEvent(ctx context.Context, targetEvent
|
||||||
if ids, ok := b.eventIDToBeforeStateIDs[targetEvent.EventID()]; ok {
|
if ids, ok := b.eventIDToBeforeStateIDs[targetEvent.EventID()]; ok {
|
||||||
return ids, nil
|
return ids, nil
|
||||||
}
|
}
|
||||||
|
if len(targetEvent.PrevEventIDs()) == 0 && targetEvent.Type() == "m.room.create" && targetEvent.StateKeyEquals("") {
|
||||||
|
util.GetLogger(ctx).WithField("room_id", targetEvent.RoomID()).Info("Backfilled to the beginning of the room")
|
||||||
|
b.eventIDToBeforeStateIDs[targetEvent.EventID()] = []string{}
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
// if we have exactly 1 prev event and we know the state of the room at that prev event, then just roll forward the prev event.
|
// if we have exactly 1 prev event and we know the state of the room at that prev event, then just roll forward the prev event.
|
||||||
// Else, we have to hit /state_ids because either we don't know the state at all at this event (new backwards extremity) or
|
// Else, we have to hit /state_ids because either we don't know the state at all at this event (new backwards extremity) or
|
||||||
// we don't know the result of state res to merge forks (2 or more prev_events)
|
// we don't know the result of state res to merge forks (2 or more prev_events)
|
||||||
|
|
|
@ -412,7 +412,14 @@ func (r *messagesReq) backfill(roomID string, fromEventIDs []string, limit int)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return res.Events, nil
|
// we may have got more than the requested limit so resize now
|
||||||
|
events := res.Events
|
||||||
|
if len(events) > limit {
|
||||||
|
// last `limit` events
|
||||||
|
events = events[len(events)-limit:]
|
||||||
|
}
|
||||||
|
|
||||||
|
return events, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// setToDefault returns the default value for the "to" query parameter of a
|
// setToDefault returns the default value for the "to" query parameter of a
|
||||||
|
|
|
@ -279,3 +279,4 @@ Inbound federation can return missing events for invite visibility
|
||||||
Inbound federation can get public room list
|
Inbound federation can get public room list
|
||||||
An event which redacts itself should be ignored
|
An event which redacts itself should be ignored
|
||||||
A pair of events which redact each other should be ignored
|
A pair of events which redact each other should be ignored
|
||||||
|
Outbound federation can backfill events
|
||||||
|
|
Loading…
Reference in a new issue