Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set_presence=offline to reduce load on upstream homeservers #290

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions sync2/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ func (v *HTTPClient) createSyncURL(since string, isFirst, toDeviceOnly bool) str
qps += "&since=" + since
}

// Set presence to offline, this potentially reduces CPU load on upstream homeservers
qps += "&set_presence=offline"

// To reduce the likelihood of a gappy v2 sync, ask for a large timeline by default.
// Synapse's default is 10; 50 is the maximum allowed, by my reading of
// https://github.com/matrix-org/synapse/blob/89a71e73905ffa1c97ae8be27d521cd2ef3f3a0c/synapse/handlers/sync.py#L576-L577
Expand Down
16 changes: 8 additions & 8 deletions sync2/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,49 +21,49 @@ func TestSyncURL(t *testing.T) {
since: "",
isFirst: false,
toDeviceOnly: false,
wantURL: wantBaseURL + `?timeout=30000&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":1}}}`),
wantURL: wantBaseURL + `?timeout=30000&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":1}}}`),
},
{
since: "",
isFirst: true,
toDeviceOnly: false,
wantURL: wantBaseURL + `?timeout=0&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":1}}}`),
wantURL: wantBaseURL + `?timeout=0&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":1}}}`),
},
{
since: "",
isFirst: false,
toDeviceOnly: true,
wantURL: wantBaseURL + `?timeout=30000&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":1}}}`),
wantURL: wantBaseURL + `?timeout=30000&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":1}}}`),
},
{
since: "",
isFirst: true,
toDeviceOnly: true,
wantURL: wantBaseURL + `?timeout=0&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":1}}}`),
wantURL: wantBaseURL + `?timeout=0&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":1}}}`),
},
{
since: "112233",
isFirst: false,
toDeviceOnly: false,
wantURL: wantBaseURL + `?timeout=30000&since=112233&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":50}}}`),
wantURL: wantBaseURL + `?timeout=30000&since=112233&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":50}}}`),
},
{
since: "112233",
isFirst: true,
toDeviceOnly: false,
wantURL: wantBaseURL + `?timeout=0&since=112233&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":50}}}`),
wantURL: wantBaseURL + `?timeout=0&since=112233&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"timeline":{"limit":50}}}`),
},
{
since: "112233",
isFirst: false,
toDeviceOnly: true,
wantURL: wantBaseURL + `?timeout=30000&since=112233&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":50}}}`),
wantURL: wantBaseURL + `?timeout=30000&since=112233&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":50}}}`),
},
{
since: "112233",
isFirst: true,
toDeviceOnly: true,
wantURL: wantBaseURL + `?timeout=0&since=112233&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":50}}}`),
wantURL: wantBaseURL + `?timeout=0&since=112233&set_presence=offline&filter=` + url.QueryEscape(`{"room":{"rooms":[],"timeline":{"limit":50}}}`),
},
}
for i, tc := range testCases {
Expand Down
Loading