If no required_state is sent; don't pull out all room state

This commit is contained in:
Kegan Dougal 2023-01-13 19:12:36 +00:00
parent f6de179c0a
commit fbc49564c9
3 changed files with 16 additions and 1 deletions

View File

@ -62,6 +62,13 @@ func (rsm *RequiredStateMap) Include(evType, stateKey string) bool {
return false
}
func (rsm *RequiredStateMap) Empty() bool {
return !rsm.allState && !rsm.lazyLoading &&
len(rsm.eventTypeToStateKeys) == 0 &&
len(rsm.stateKeysForWildcardEventType) == 0 &&
len(rsm.eventTypesWithWildcardStateKeys) == 0
}
// work out what to ask the storage layer: if we have wildcard event types we need to pull all
// room state and cannot only pull out certain event types. If we have wildcard state keys we
// need to use an empty list for state keys.

View File

@ -140,6 +140,9 @@ func (c *GlobalCache) LoadRoomState(ctx context.Context, roomIDs []string, loadP
if c.store == nil {
return nil
}
if requiredStateMap.Empty() {
return nil
}
resultMap := make(map[string][]json.RawMessage, len(roomIDs))
roomIDToStateEvents, err := c.store.RoomStateAfterEventPosition(ctx, roomIDs, loadPosition, requiredStateMap.QueryStateMap())
if err != nil {

View File

@ -405,7 +405,9 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
}
rsm := roomSub.RequiredStateMap(s.userID)
roomIDToState := s.globalCache.LoadRoomState(ctx, roomIDs, s.loadPosition, rsm, roomToUsersInTimeline)
if roomIDToState == nil { // e.g no required_state
roomIDToState = make(map[string][]json.RawMessage)
}
for _, roomID := range roomIDs {
userRoomData, ok := roomIDToUserRoomData[roomID]
if !ok {
@ -423,6 +425,9 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
var requiredState []json.RawMessage
if !userRoomData.IsInvite {
requiredState = roomIDToState[roomID]
if requiredState == nil {
requiredState = make([]json.RawMessage, 0)
}
}
prevBatch, _ := userRoomData.PrevBatch()
rooms[roomID] = sync3.Room{