mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
partial sync requests WIP
This commit is contained in:
parent
7f8b19aee4
commit
69353f12b5
@ -162,6 +162,8 @@ function update(req) {
|
|||||||
|
|
||||||
partialRequests[requestId].payload += req.body;
|
partialRequests[requestId].payload += req.body;
|
||||||
|
|
||||||
|
log.info(`Receiving partial request ${requestId}, page index ${pageIndex} out of ${pageCount} pages.`);
|
||||||
|
|
||||||
if (pageIndex !== pageCount - 1) {
|
if (pageIndex !== pageCount - 1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -180,7 +182,9 @@ function update(req) {
|
|||||||
|
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
for (const key in partialRequests) {
|
for (const key in partialRequests) {
|
||||||
if (partialRequests[key].createdAt - Date.now() > 5 * 60 * 1000) {
|
if (Date.now() - partialRequests[key].createdAt > 5 * 60 * 1000) {
|
||||||
|
log.info(`Cleaning up unfinished partial requests for ${key}`);
|
||||||
|
|
||||||
delete partialRequests[key];
|
delete partialRequests[key];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,8 @@ function exec(opts) {
|
|||||||
if (!opts.paging) {
|
if (!opts.paging) {
|
||||||
opts.paging = {
|
opts.paging = {
|
||||||
pageCount: 1,
|
pageCount: 1,
|
||||||
pageIndex: 0
|
pageIndex: 0,
|
||||||
|
requestId: 'n/a'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -28,13 +29,13 @@ function exec(opts) {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
try {
|
try {
|
||||||
const headers = Object.assign({
|
const headers = {
|
||||||
Cookie: (opts.cookieJar && opts.cookieJar.header) || "",
|
Cookie: (opts.cookieJar && opts.cookieJar.header) || "",
|
||||||
'Content-Type': opts.paging.pageCount === 1 ? 'application/json' : 'text/plain',
|
'Content-Type': opts.paging.pageCount === 1 ? 'application/json' : 'text/plain',
|
||||||
pageCount: opts.pageCount,
|
pageCount: opts.paging.pageCount,
|
||||||
pageIndex: opts.pageIndex,
|
pageIndex: opts.paging.pageIndex,
|
||||||
requestId: opts.requestId
|
requestId: opts.paging.requestId
|
||||||
}, opts.headers || {});
|
};
|
||||||
|
|
||||||
if (opts.auth) {
|
if (opts.auth) {
|
||||||
const token = Buffer.from(opts.auth.user + ":" + opts.auth.pass).toString('base64');
|
const token = Buffer.from(opts.auth.user + ":" + opts.auth.pass).toString('base64');
|
||||||
@ -85,7 +86,7 @@ function exec(opts) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
request.end(opts.body ? JSON.stringify(opts.body) : undefined);
|
request.end(opts.body);
|
||||||
}
|
}
|
||||||
catch (e) {
|
catch (e) {
|
||||||
reject(generateError(opts, e.message));
|
reject(generateError(opts, e.message));
|
||||||
|
@ -253,13 +253,15 @@ async function checkContentHash(syncContext) {
|
|||||||
return failedChecks.length > 0;
|
return failedChecks.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function syncRequest(syncContext, method, requestPath, body = '') {
|
async function syncRequest(syncContext, method, requestPath, body) {
|
||||||
|
body = body ? JSON.stringify(body) : '';
|
||||||
|
|
||||||
const timeout = syncOptions.getSyncTimeout();
|
const timeout = syncOptions.getSyncTimeout();
|
||||||
|
|
||||||
let response;
|
let response;
|
||||||
|
|
||||||
const requestId = utils.randomString(10);
|
const requestId = utils.randomString(10);
|
||||||
const pageCount = Math.ceil(body.length / 1000000);
|
const pageCount = Math.min(1, Math.ceil(body.length / 1000000));
|
||||||
|
|
||||||
for (let pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
for (let pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
||||||
const opts = {
|
const opts = {
|
||||||
@ -277,9 +279,11 @@ async function syncRequest(syncContext, method, requestPath, body = '') {
|
|||||||
};
|
};
|
||||||
|
|
||||||
response = await utils.timeLimit(request.exec(opts), timeout);
|
response = await utils.timeLimit(request.exec(opts), timeout);
|
||||||
|
|
||||||
|
console.log("response", response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEntityChangeRow(entityName, entityId) {
|
function getEntityChangeRow(entityName, entityId) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user