mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-31 13:22:46 +00:00
Limit JoinedUsersSetInRooms
to interested users (#2234)
* Limit database work in `JoinedUsersSetInRooms` to changed user IDs only * Comments * Fix variadic params for SQLite, update comments
This commit is contained in:
parent
58bf91a585
commit
530f05885d
8 changed files with 49 additions and 31 deletions
|
@ -82,7 +82,16 @@ func DeviceListCatchup(
|
|||
util.GetLogger(ctx).WithError(queryRes.Error).Error("QueryKeyChanges failed")
|
||||
return to, hasNew, nil
|
||||
}
|
||||
// QueryKeyChanges gets ALL users who have changed keys, we want the ones who share rooms with the user.
|
||||
|
||||
// Work out which user IDs we care about — that includes those in the original request,
|
||||
// the response from QueryKeyChanges (which includes ALL users who have changed keys)
|
||||
// as well as every user who has a join or leave event in the current sync response. We
|
||||
// will request information about which rooms these users are joined to, so that we can
|
||||
// see if we still share any rooms with them.
|
||||
joinUserIDs, leaveUserIDs := membershipEvents(res)
|
||||
queryRes.UserIDs = append(queryRes.UserIDs, joinUserIDs...)
|
||||
queryRes.UserIDs = append(queryRes.UserIDs, leaveUserIDs...)
|
||||
queryRes.UserIDs = util.UniqueStrings(queryRes.UserIDs)
|
||||
var sharedUsersMap map[string]int
|
||||
sharedUsersMap, queryRes.UserIDs = filterSharedUsers(ctx, rsAPI, userID, queryRes.UserIDs)
|
||||
util.GetLogger(ctx).Debugf(
|
||||
|
@ -100,9 +109,8 @@ func DeviceListCatchup(
|
|||
userSet[userID] = true
|
||||
}
|
||||
}
|
||||
// if the response has any join/leave events, add them now.
|
||||
// Finally, add in users who have joined or left.
|
||||
// TODO: This is sub-optimal because we will add users to `changed` even if we already shared a room with them.
|
||||
joinUserIDs, leaveUserIDs := membershipEvents(res)
|
||||
for _, userID := range joinUserIDs {
|
||||
if !userSet[userID] {
|
||||
res.DeviceLists.Changed = append(res.DeviceLists.Changed, userID)
|
||||
|
@ -213,7 +221,8 @@ func filterSharedUsers(
|
|||
var result []string
|
||||
var sharedUsersRes roomserverAPI.QuerySharedUsersResponse
|
||||
err := rsAPI.QuerySharedUsers(ctx, &roomserverAPI.QuerySharedUsersRequest{
|
||||
UserID: userID,
|
||||
UserID: userID,
|
||||
OtherUserIDs: usersWithChangedKeys,
|
||||
}, &sharedUsersRes)
|
||||
if err != nil {
|
||||
// default to all users so we do needless queries rather than miss some important device update
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue