aboutsummaryrefslogtreecommitdiff
path: root/syncapi/sync
diff options
context:
space:
mode:
authorAlex Chen <Cnly@users.noreply.github.com>2019-08-01 12:36:13 +0800
committerGitHub <noreply@github.com>2019-08-01 12:36:13 +0800
commit3578d77d259c852a16dc430725d348e2c62c4ff5 (patch)
tree1543669adf93a8cc1f5efbabd834f8f9385f9945 /syncapi/sync
parent0dcf0a7d64b0ba42560fe8b4aa1c65d36a0344c3 (diff)
Implement "full_state" query parameter for /sync (#751)
Closes #637.
Diffstat (limited to 'syncapi/sync')
-rw-r--r--syncapi/sync/requestpool.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/syncapi/sync/requestpool.go b/syncapi/sync/requestpool.go
index a6ec6bd9..d773a460 100644
--- a/syncapi/sync/requestpool.go
+++ b/syncapi/sync/requestpool.go
@@ -65,8 +65,7 @@ func (rp *RequestPool) OnIncomingSyncRequest(req *http.Request, device *authtype
currPos := rp.notifier.CurrentPosition()
- // If this is an initial sync or timeout=0 we return immediately
- if syncReq.since == nil || syncReq.timeout == 0 {
+ if shouldReturnImmediately(syncReq) {
syncData, err = rp.currentSyncForUser(*syncReq, currPos)
if err != nil {
return httputil.LogThenError(req, err)
@@ -135,7 +134,7 @@ func (rp *RequestPool) currentSyncForUser(req syncRequest, latestPos types.SyncP
if req.since == nil {
res, err = rp.db.CompleteSync(req.ctx, req.device.UserID, req.limit)
} else {
- res, err = rp.db.IncrementalSync(req.ctx, req.device, *req.since, latestPos, req.limit)
+ res, err = rp.db.IncrementalSync(req.ctx, req.device, *req.since, latestPos, req.limit, req.wantFullState)
}
if err != nil {
@@ -216,3 +215,10 @@ func (rp *RequestPool) appendAccountData(
return data, nil
}
+
+// shouldReturnImmediately returns whether the /sync request is an initial sync,
+// or timeout=0, or full_state=true, in any of the cases the request should
+// return immediately.
+func shouldReturnImmediately(syncReq *syncRequest) bool {
+ return syncReq.since == nil || syncReq.timeout == 0 || syncReq.wantFullState
+}