Parallelise PDU stream fetching for complete sync

This commit is contained in:
Neil Alexander 2021-01-29 12:53:18 +00:00
parent 6d1c6f29e0
commit 9b6e807f82
No known key found for this signature in database
GPG key ID: A02A2019A2BB0944

View file

@ -52,7 +52,12 @@ func (p *PDUStreamProvider) CompleteSync(
eventFilter := req.Filter.Room.Timeline
// Build up a /sync response. Add joined rooms.
var reqMutex sync.Mutex
var reqWaitGroup sync.WaitGroup
reqWaitGroup.add(len(joinedRooms))
for _, roomID := range joinedRoomIDs {
go func() {
defer reqWaitGroup.Done()
var jr *types.JoinResponse
jr, err = p.getJoinResponseForCompleteSync(
ctx, roomID, r, &stateFilter, &eventFilter, req.Device,
@ -61,8 +66,11 @@ func (p *PDUStreamProvider) CompleteSync(
req.Log.WithError(err).Error("p.getJoinResponseForCompleteSync failed")
return from
}
reqMutex.Lock()
defer reqMutex.Unlock()
req.Response.Rooms.Join[roomID] = *jr
req.Rooms[roomID] = gomatrixserverlib.Join
}()
}
// Add peeked rooms.