mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-17 03:43:11 -06:00
Prevent roomserver query API from trying to handle requests for stub rooms
This commit is contained in:
parent
c9b9304f61
commit
7b73571dab
|
|
@ -61,6 +61,14 @@ func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
|
||||||
if roomNID == 0 {
|
if roomNID == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
isStub, err := r.DB.IsRoomStub(ctx, roomNID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if isStub {
|
||||||
|
response.RoomExists = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
response.RoomExists = true
|
response.RoomExists = true
|
||||||
response.RoomVersion = roomVersion
|
response.RoomVersion = roomVersion
|
||||||
|
|
||||||
|
|
@ -121,6 +129,14 @@ func (r *RoomserverQueryAPI) QueryStateAfterEvents(
|
||||||
if roomNID == 0 {
|
if roomNID == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
isStub, err := r.DB.IsRoomStub(ctx, roomNID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if isStub {
|
||||||
|
response.RoomExists = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
response.RoomExists = true
|
response.RoomExists = true
|
||||||
response.RoomVersion = roomVersion
|
response.RoomVersion = roomVersion
|
||||||
|
|
||||||
|
|
@ -656,6 +672,14 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
|
||||||
if roomNID == 0 {
|
if roomNID == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
isStub, err := r.DB.IsRoomStub(ctx, roomNID)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if isStub {
|
||||||
|
response.RoomExists = false
|
||||||
|
return nil
|
||||||
|
}
|
||||||
response.RoomExists = true
|
response.RoomExists = true
|
||||||
|
|
||||||
roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, request.RoomID)
|
roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, request.RoomID)
|
||||||
|
|
|
||||||
|
|
@ -83,4 +83,5 @@ type Database interface {
|
||||||
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool) ([]types.EventNID, error)
|
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool) ([]types.EventNID, error)
|
||||||
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
||||||
GetRoomVersionForRoom(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, error)
|
GetRoomVersionForRoom(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, error)
|
||||||
|
IsRoomStub(ctx context.Context, roomNID types.RoomNID) (bool, error)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -772,6 +772,16 @@ func (d *Database) GetRoomVersionForRoomNID(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Database) IsRoomStub(
|
||||||
|
ctx context.Context, roomNID types.RoomNID,
|
||||||
|
) (bool, error) {
|
||||||
|
nids, _, err := d.statements.selectLatestEventNIDs(ctx, roomNID)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return len(nids) == 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
type transaction struct {
|
type transaction struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
txn *sql.Tx
|
txn *sql.Tx
|
||||||
|
|
|
||||||
|
|
@ -926,6 +926,16 @@ func (d *Database) GetRoomVersionForRoomNID(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d *Database) IsRoomStub(
|
||||||
|
ctx context.Context, roomNID types.RoomNID,
|
||||||
|
) (bool, error) {
|
||||||
|
nids, _, err := d.statements.selectLatestEventNIDs(ctx, nil, roomNID)
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
return len(nids) == 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
type transaction struct {
|
type transaction struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
txn *sql.Tx
|
txn *sql.Tx
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue