mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-31 18:53:10 -06:00
Don't do unnecessary work for rooms that don't exist
This commit is contained in:
parent
9c5f38f9e5
commit
ef963799e0
|
|
@ -128,9 +128,17 @@ func (r *Inputer) processRoomEvent(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Don't waste time processing the event if the room doesn't exist.
|
||||||
|
// A room entry locally will only be created in response to a create
|
||||||
|
// event.
|
||||||
|
isCreateEvent := event.Type() == gomatrixserverlib.MRoomCreate && event.StateKeyEquals("")
|
||||||
|
if !updater.RoomExists() && !isCreateEvent {
|
||||||
|
return rollbackTransaction, fmt.Errorf("room does not exist")
|
||||||
|
}
|
||||||
|
|
||||||
var missingAuth, missingPrev bool
|
var missingAuth, missingPrev bool
|
||||||
serverRes := &fedapi.QueryJoinedHostServerNamesInRoomResponse{}
|
serverRes := &fedapi.QueryJoinedHostServerNamesInRoomResponse{}
|
||||||
if event.Type() != gomatrixserverlib.MRoomCreate || !event.StateKeyEquals("") {
|
if !isCreateEvent {
|
||||||
missingAuthIDs, missingPrevIDs, err := updater.MissingAuthPrevEvents(ctx, event)
|
missingAuthIDs, missingPrevIDs, err := updater.MissingAuthPrevEvents(ctx, event)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return rollbackTransaction, fmt.Errorf("updater.MissingAuthPrevEvents: %w", err)
|
return rollbackTransaction, fmt.Errorf("updater.MissingAuthPrevEvents: %w", err)
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ type RoomUpdater struct {
|
||||||
latestEvents []types.StateAtEventAndReference
|
latestEvents []types.StateAtEventAndReference
|
||||||
lastEventIDSent string
|
lastEventIDSent string
|
||||||
currentStateSnapshotNID types.StateSnapshotNID
|
currentStateSnapshotNID types.StateSnapshotNID
|
||||||
|
roomExists bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func rollback(txn *sql.Tx) {
|
func rollback(txn *sql.Tx) {
|
||||||
|
|
@ -33,7 +34,7 @@ func NewRoomUpdater(ctx context.Context, d *Database, txn *sql.Tx, roomInfo *typ
|
||||||
// succeed, processing a create event which creates the room, or it won't.
|
// succeed, processing a create event which creates the room, or it won't.
|
||||||
if roomInfo == nil {
|
if roomInfo == nil {
|
||||||
return &RoomUpdater{
|
return &RoomUpdater{
|
||||||
transaction{ctx, txn}, d, nil, nil, "", 0,
|
transaction{ctx, txn}, d, nil, nil, "", 0, false,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,10 +58,15 @@ func NewRoomUpdater(ctx context.Context, d *Database, txn *sql.Tx, roomInfo *typ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return &RoomUpdater{
|
return &RoomUpdater{
|
||||||
transaction{ctx, txn}, d, roomInfo, stateAndRefs, lastEventIDSent, currentStateSnapshotNID,
|
transaction{ctx, txn}, d, roomInfo, stateAndRefs, lastEventIDSent, currentStateSnapshotNID, true,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RoomExists returns true if the room exists and false otherwise.
|
||||||
|
func (u *RoomUpdater) RoomExists() bool {
|
||||||
|
return u.roomExists
|
||||||
|
}
|
||||||
|
|
||||||
// Implements sqlutil.Transaction
|
// Implements sqlutil.Transaction
|
||||||
func (u *RoomUpdater) Commit() error {
|
func (u *RoomUpdater) Commit() error {
|
||||||
if u.txn == nil { // SQLite mode probably
|
if u.txn == nil { // SQLite mode probably
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue