Skip to content

Commit

Permalink
Merge pull request #273 from matrix-org/s7evink/roomstateperfv2
Browse files Browse the repository at this point in the history
Use the userCache to check if the user is invited
  • Loading branch information
S7evinK authored Aug 24, 2023
2 parents cb7dac8 + 2521d9c commit 3ce665d
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 27 deletions.
4 changes: 0 additions & 4 deletions sync3/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ func (d *Dispatcher) IsUserJoined(userID, roomID string) bool {
return d.jrt.IsUserJoined(userID, roomID)
}

func (d *Dispatcher) IsUserInvited(userID, roomID string) bool {
return d.jrt.IsUserInvited(userID, roomID)
}

// Load joined members into the dispatcher.
// MUST BE CALLED BEFORE V2 POLL LOOPS START.
func (d *Dispatcher) Startup(roomToJoinedUsers map[string][]string) error {
Expand Down
4 changes: 2 additions & 2 deletions sync3/handler/connstate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (

type JoinChecker interface {
IsUserJoined(userID, roomID string) bool
IsUserInvited(userID, roomID string) bool
}

// ConnState tracks all high-level connection state for this connection, like the combined request
Expand Down Expand Up @@ -596,7 +595,8 @@ func (s *ConnState) getInitialRoomData(ctx context.Context, roomSub sync3.RoomSu
// since we'll be using the invite_state only.
loadRoomIDs := make([]string, 0, len(roomIDs))
for _, roomID := range roomIDs {
if !s.joinChecker.IsUserInvited(s.userID, roomID) {
userRoomData, ok := roomIDToUserRoomData[roomID]
if !ok || !userRoomData.IsInvite {
loadRoomIDs = append(loadRoomIDs, roomID)
}
}
Expand Down
4 changes: 0 additions & 4 deletions sync3/handler/connstate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ func (t *NopJoinTracker) IsUserJoined(userID, roomID string) bool {
return true
}

func (t *NopJoinTracker) IsUserInvited(userID, roomID string) bool {
return true
}

type NopTransactionFetcher struct{}

func (t *NopTransactionFetcher) TransactionIDForEvents(userID, deviceID string, eventIDs []string) (eventIDToTxnID map[string]string) {
Expand Down
12 changes: 0 additions & 12 deletions sync3/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,18 +179,6 @@ func (t *JoinedRoomsTracker) UsersInvitedToRoom(userIDs []string, roomID string)
t.roomIDToInvitedUsers[roomID] = users
}

func (t *JoinedRoomsTracker) IsUserInvited(userID, roomID string) bool {
t.mu.RLock()
defer t.mu.RUnlock()
users := t.roomIDToInvitedUsers[roomID]
for u := range users {
if u == userID {
return true
}
}
return false
}

func (t *JoinedRoomsTracker) NumInvitedUsersForRoom(roomID string) int {
t.mu.RLock()
defer t.mu.RUnlock()
Expand Down
5 changes: 0 additions & 5 deletions sync3/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,15 @@ func TestTracker(t *testing.T) {

jrt.UsersInvitedToRoom([]string{"alice"}, "room4")
assertNumEquals(t, jrt.NumInvitedUsersForRoom("room4"), 1)
assertBool(t, "expected alice to be invited", jrt.IsUserInvited("alice", "room4"), true)
jrt.UserJoinedRoom("alice", "room4")
assertNumEquals(t, jrt.NumInvitedUsersForRoom("room4"), 0)
assertBool(t, "expected alice to be not invited anymore", jrt.IsUserInvited("alice", "room4"), false)
jrt.UserJoinedRoom("alice", "room4") // dupe joins don't bother it
assertNumEquals(t, jrt.NumInvitedUsersForRoom("room4"), 0)
jrt.UsersInvitedToRoom([]string{"bob"}, "room4")
assertNumEquals(t, jrt.NumInvitedUsersForRoom("room4"), 1)
jrt.UsersInvitedToRoom([]string{"bob"}, "room4") // dupe invites don't bother it
assertNumEquals(t, jrt.NumInvitedUsersForRoom("room4"), 1)
jrt.UserLeftRoom("bob", "room4")
assertNumEquals(t, jrt.NumInvitedUsersForRoom("room4"), 0)

assertBool(t, "expected unknown user to be not invited", jrt.IsUserInvited("doesnotexist", "room3"), false)
}

func TestTrackerStartup(t *testing.T) {
Expand Down

0 comments on commit 3ce665d

Please sign in to comment.