Check that we have a populated state snapshot when determining if we closed the gap

This commit is contained in:
Neil Alexander 2022-02-08 17:23:38 +00:00
parent 2771d93748
commit 92494e1f61
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944
2 changed files with 3 additions and 1 deletions

View file

@ -486,7 +486,7 @@ Event:
// now check if we can fill the gap. Look to see if we have state snapshot IDs for the earliest event
earliestNewEvent := newEvents[0]
if state, err := t.db.StateAtEventIDs(ctx, []string{earliestNewEvent.EventID()}); err != nil || len(state) == 0 {
if state, err := t.db.StateAtEventIDs(ctx, []string{earliestNewEvent.EventID()}); err != nil || len(state) == 0 || state[0].BeforeStateSnapshotNID == 0 {
if earliestNewEvent.Type() == gomatrixserverlib.MRoomCreate && earliestNewEvent.StateKeyEquals("") {
// we got to the beginning of the room so there will be no state! It's all good we can process this
return newEvents, true, nil

View file

@ -603,6 +603,8 @@ func (d *Database) storeEvent(
if err == sql.ErrNoRows {
// We've already inserted the event so select the numeric event ID
eventNID, stateNID, err = d.EventsTable.SelectEvent(ctx, txn, event.EventID())
} else if err != nil {
return fmt.Errorf("d.EventsTable.InsertEvent: %w", err)
}
if err != nil {
return fmt.Errorf("d.EventsTable.SelectEvent: %w", err)