mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 19:33:09 -06:00
Replace IsRoomStub with RoomNIDExcludingStubs, fix query API to use that instead
This commit is contained in:
parent
e5fb25ac02
commit
35845e4ea3
|
|
@ -54,21 +54,13 @@ func (r *RoomserverQueryAPI) QueryLatestEventsAndState(
|
|||
roomState := state.NewStateResolution(r.DB)
|
||||
|
||||
response.QueryLatestEventsAndStateRequest = *request
|
||||
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||
roomNID, err := r.DB.RoomNIDExcludingStubs(ctx, request.RoomID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if roomNID == 0 {
|
||||
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.RoomVersion = roomVersion
|
||||
|
||||
|
|
@ -122,21 +114,13 @@ func (r *RoomserverQueryAPI) QueryStateAfterEvents(
|
|||
roomState := state.NewStateResolution(r.DB)
|
||||
|
||||
response.QueryStateAfterEventsRequest = *request
|
||||
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||
roomNID, err := r.DB.RoomNIDExcludingStubs(ctx, request.RoomID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if roomNID == 0 {
|
||||
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.RoomVersion = roomVersion
|
||||
|
||||
|
|
@ -665,21 +649,13 @@ func (r *RoomserverQueryAPI) QueryStateAndAuthChain(
|
|||
response *api.QueryStateAndAuthChainResponse,
|
||||
) error {
|
||||
response.QueryStateAndAuthChainRequest = *request
|
||||
roomNID, err := r.DB.RoomNID(ctx, request.RoomID)
|
||||
roomNID, err := r.DB.RoomNIDExcludingStubs(ctx, request.RoomID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if roomNID == 0 {
|
||||
return nil
|
||||
}
|
||||
isStub, err := r.DB.IsRoomStub(ctx, roomNID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if isStub {
|
||||
response.RoomExists = false
|
||||
return nil
|
||||
}
|
||||
response.RoomExists = true
|
||||
|
||||
roomVersion, err := r.DB.GetRoomVersionForRoom(ctx, request.RoomID)
|
||||
|
|
|
|||
|
|
@ -71,6 +71,10 @@ type Database interface {
|
|||
GetLatestEventsForUpdate(ctx context.Context, roomNID types.RoomNID) (types.RoomRecentEventsUpdater, error)
|
||||
GetTransactionEventID(ctx context.Context, transactionID string, sessionID int64, userID string) (string, error)
|
||||
RoomNID(ctx context.Context, roomID string) (types.RoomNID, error)
|
||||
// RoomNIDExcludingStubs is a special variation of RoomNID that will return 0 as if the room
|
||||
// does not exist if the room has no latest events. This can happen when we've received an
|
||||
// invite over federation for a room that we don't know anything else about yet.
|
||||
RoomNIDExcludingStubs(ctx context.Context, roomID string) (types.RoomNID, error)
|
||||
LatestEventIDs(ctx context.Context, roomNID types.RoomNID) ([]gomatrixserverlib.EventReference, types.StateSnapshotNID, int64, error)
|
||||
GetInvitesForUser(ctx context.Context, roomNID types.RoomNID, targetUserNID types.EventStateKeyNID) (senderUserIDs []types.EventStateKeyNID, err error)
|
||||
SetRoomAlias(ctx context.Context, alias string, roomID string, creatorUserID string) error
|
||||
|
|
@ -83,5 +87,4 @@ type Database interface {
|
|||
GetMembershipEventNIDsForRoom(ctx context.Context, roomNID types.RoomNID, joinOnly bool) ([]types.EventNID, error)
|
||||
EventsFromIDs(ctx context.Context, eventIDs []string) ([]types.Event, error)
|
||||
GetRoomVersionForRoom(ctx context.Context, roomID string) (gomatrixserverlib.RoomVersion, error)
|
||||
IsRoomStub(ctx context.Context, roomNID types.RoomNID) (bool, error)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -471,6 +471,23 @@ func (d *Database) RoomNID(ctx context.Context, roomID string) (types.RoomNID, e
|
|||
return roomNID, err
|
||||
}
|
||||
|
||||
// RoomNIDExcludingStubs implements query.RoomserverQueryAPIDB
|
||||
func (d *Database) RoomNIDExcludingStubs(ctx context.Context, roomID string) (roomNID types.RoomNID, err error) {
|
||||
roomNID, err = d.RoomNID(ctx, roomID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
latestEvents, _, err := d.statements.selectLatestEventNIDs(ctx, roomNID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(latestEvents) == 0 {
|
||||
roomNID = 0
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LatestEventIDs implements query.RoomserverQueryAPIDatabase
|
||||
func (d *Database) LatestEventIDs(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
|
|
@ -772,16 +789,6 @@ 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 {
|
||||
ctx context.Context
|
||||
txn *sql.Tx
|
||||
|
|
|
|||
|
|
@ -590,6 +590,23 @@ func (d *Database) RoomNID(ctx context.Context, roomID string) (roomNID types.Ro
|
|||
return
|
||||
}
|
||||
|
||||
// RoomNIDExcludingStubs implements query.RoomserverQueryAPIDB
|
||||
func (d *Database) RoomNIDExcludingStubs(ctx context.Context, roomID string) (roomNID types.RoomNID, err error) {
|
||||
roomNID, err = d.RoomNID(ctx, roomID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
latestEvents, _, err := d.statements.selectLatestEventNIDs(ctx, nil, roomNID)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if len(latestEvents) == 0 {
|
||||
roomNID = 0
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// LatestEventIDs implements query.RoomserverQueryAPIDatabase
|
||||
func (d *Database) LatestEventIDs(
|
||||
ctx context.Context, roomNID types.RoomNID,
|
||||
|
|
@ -926,16 +943,6 @@ 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 {
|
||||
ctx context.Context
|
||||
txn *sql.Tx
|
||||
|
|
|
|||
Loading…
Reference in a new issue