mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-16 03:13:11 -06:00
Put the loop and the IsEmpty() check back in sync handler
This commit is contained in:
parent
bff549b94b
commit
deb181ea50
|
|
@ -86,33 +86,37 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
|
||||||
userStreamListener := rp.notifier.GetListener(*syncReq)
|
userStreamListener := rp.notifier.GetListener(*syncReq)
|
||||||
defer userStreamListener.Close()
|
defer userStreamListener.Close()
|
||||||
|
|
||||||
select {
|
for {
|
||||||
// Wait for notifier to wake us up
|
select {
|
||||||
case <-userStreamListener.GetNotifyChannel(currPos):
|
// Wait for notifier to wake us up
|
||||||
currPos = userStreamListener.GetStreamPosition()
|
case <-userStreamListener.GetNotifyChannel(currPos):
|
||||||
// Or for timeout to expire
|
currPos = userStreamListener.GetStreamPosition()
|
||||||
case <-timer.C:
|
// Or for timeout to expire
|
||||||
// We just need to ensure we get out of the select after reaching the
|
case <-timer.C:
|
||||||
// timeout, but there's nothing specific we want to do in this case
|
// We just need to ensure we get out of the select after reaching the
|
||||||
// apart from that, so we do nothing.
|
// timeout, but there's nothing specific we want to do in this case
|
||||||
// Or for the request to be cancelled
|
// apart from that, so we do nothing.
|
||||||
case <-req.Context().Done():
|
// Or for the request to be cancelled
|
||||||
return httputil.LogThenError(req, req.Context().Err())
|
case <-req.Context().Done():
|
||||||
}
|
return httputil.LogThenError(req, req.Context().Err())
|
||||||
|
}
|
||||||
|
|
||||||
// Note that we don't time out during calculation of sync
|
// Note that we don't time out during calculation of sync
|
||||||
// response. This ensures that we don't waste the hard work
|
// response. This ensures that we don't waste the hard work
|
||||||
// of calculating the sync only to get timed out before we
|
// of calculating the sync only to get timed out before we
|
||||||
// can respond
|
// can respond
|
||||||
|
|
||||||
syncData, err = rp.currentSyncForUser(*syncReq, currPos)
|
syncData, err = rp.currentSyncForUser(*syncReq, currPos)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httputil.LogThenError(req, err)
|
return httputil.LogThenError(req, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return util.JSONResponse{
|
if !syncData.IsEmpty() {
|
||||||
Code: http.StatusOK,
|
return util.JSONResponse{
|
||||||
JSON: syncData,
|
Code: http.StatusOK,
|
||||||
|
JSON: syncData,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue