Deduplicate transactions

This commit is contained in:
Neil Alexander 2020-06-01 09:25:57 +01:00
parent 5cf900428c
commit dddc9efe3e
2 changed files with 10 additions and 8 deletions

View file

@ -33,13 +33,11 @@ func SendToDevice(
eventType string, txnID *string,
) util.JSONResponse {
if txnID != nil {
// Try to fetch response from transactionsCache
if res, ok := txnCache.FetchTransaction(device.AccessToken, *txnID); ok {
return *res
}
}
// parse the incoming http request
var httpReq struct {
Messages map[string]map[string]json.RawMessage `json:"messages"`
}
@ -59,8 +57,14 @@ func SendToDevice(
}
}
return util.JSONResponse{
res := util.JSONResponse{
Code: http.StatusOK,
JSON: struct{}{},
}
if txnID != nil {
txnCache.AddTransaction(device.AccessToken, *txnID, &res)
}
return res
}

View file

@ -174,11 +174,9 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.Strea
// This is a bit of a hack until we can do something better with the sync API
// than this mess. If we have pending send-to-device updates then we want to
// deliver them pretty quickly. We still want the next step to run so that the
// sync tokens are updated properly. Set a short timeout on the next step so
// that we return faster.
ctx, cancel := context.WithTimeout(req.ctx, time.Second)
defer cancel()
req.ctx = ctx
// sync tokens are updated properly. Set a zero timeout on the next step so
// that we return immediately.
req.timeout = 0
}
// TODO: handle ignored users