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

Desktop: Speed up Webdav Sync on Linux #2577

Merged
merged 7 commits into from
Feb 27, 2020
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
6 changes: 5 additions & 1 deletion ReactNativeClient/lib/WebDavApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const URL = require('url-parse');
const { rtrimSlashes } = require('lib/path-utils.js');
const base64 = require('base-64');


// Note that the d: namespace (the DAV namespace) is specific to Nextcloud. The RFC for example uses "D:" however
// we make all the tags and attributes lowercase so we handle both the Nextcloud style and RFC. Hopefully other
// implementations use the same namespaces. If not, extra processing can be done in `nameProcessor`, for
Expand All @@ -31,6 +32,7 @@ class WebDavApi {
options.headers = Object.assign({}, options.headers);
if (options.headers['Authorization']) options.headers['Authorization'] = '********';
delete options.method;
delete options.agent;
output.push(JSON.stringify(options));
return output.join(' ');
};
Expand Down Expand Up @@ -359,9 +361,11 @@ class WebDavApi {
fetchOptions.method = method;
if (options.path) fetchOptions.path = options.path;
if (body) fetchOptions.body = body;

const url = `${this.baseUrl()}/${path}`;

if (shim.httpAgent(url)) fetchOptions.agent = shim.httpAgent(url);


let response = null;

// console.info('WebDAV Call', `${method} ${url}`, headers, options);
Expand Down
20 changes: 20 additions & 0 deletions ReactNativeClient/lib/shim-init-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const Note = require('lib/models/Note.js');
const Resource = require('lib/models/Resource.js');
const urlValidator = require('valid-url');
const { _ } = require('lib/locale.js');
const http = require('http');
const https = require('https');

tessus marked this conversation as resolved.
Show resolved Hide resolved
function shimInit() {
shim.fsDriver = () => {
Expand Down Expand Up @@ -363,6 +365,24 @@ function shimInit() {
return bridge().openExternal(url);
};

shim.httpAgent_ = null;

shim.httpAgent = url => {
if (shim.isLinux() && !shim.httpAgent) {
var AgentSettings = {
keepAlive: true,
maxSockets: 1,
keepAliveMsecs: 5000,
};
if (url.startsWith('https')) {
shim.httpAgent_ = new https.Agent(AgentSettings);
} else {
shim.httpAgent_ = new http.Agent(AgentSettings);
}
}
return shim.httpAgent_;
};

shim.openOrCreateFile = (filepath, defaultContents) => {
// If the file doesn't exist, create it
if (!fs.existsSync(filepath)) {
Expand Down
4 changes: 4 additions & 0 deletions ReactNativeClient/lib/shim-init-react.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ function shimInit() {
Linking.openURL(url);
};

shim.httpAgent = () => {
return null;
};

shim.waitForFrame = () => {
return new Promise(function(resolve) {
requestAnimationFrame(function() {
Expand Down
3 changes: 3 additions & 0 deletions ReactNativeClient/lib/shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ shim.Buffer = null;
shim.openUrl = () => {
throw new Error('Not implemented');
};
shim.httpAgent = () => {
throw new Error('Not implemented');
};
shim.openOrCreateFile = () => {
throw new Error('Not implemented');
};
Expand Down