fixed waitForSync

This commit is contained in:
zadam 2020-03-09 22:32:26 +01:00
parent 1d78432df4
commit bcbf1b79c3
4 changed files with 21 additions and 16 deletions

20
package-lock.json generated
View File

@ -1,6 +1,6 @@
{
"name": "trilium",
"version": "0.40.4",
"version": "0.40.5",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
@ -2113,9 +2113,9 @@
"integrity": "sha1-QGXiATz5+5Ft39gu+1Bq1MZ2kGI="
},
"dayjs": {
"version": "1.8.21",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.21.tgz",
"integrity": "sha512-1kbWK0hziklUHkGgiKr7xm59KwAg/K3Tp7H/8X+f58DnNCwY3pKYjOCJpIlVs125FRBukGVZdKZojC073D0IeQ=="
"version": "1.8.22",
"resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.8.22.tgz",
"integrity": "sha512-N8IXfxBD62Y9cKTuuuSoOlCXRnnzaTj1vu91r855iq6FbY5cZqOZnW/95nUn6kJiR+W9PHHrLykEoQOe6fUKxQ=="
},
"debug": {
"version": "4.1.1",
@ -7009,9 +7009,9 @@
"integrity": "sha1-ofeDj4MUxRbwXs78vEzP4EtO14k="
},
"open": {
"version": "7.0.2",
"resolved": "https://registry.npmjs.org/open/-/open-7.0.2.tgz",
"integrity": "sha512-70E/pFTPr7nZ9nLDPNTcj3IVqnNvKuP4VsBmoKV9YGTnChe0mlS3C4qM7qKarhZ8rGaHKLfo+vBTHXDp6ZSyLQ==",
"version": "7.0.3",
"resolved": "https://registry.npmjs.org/open/-/open-7.0.3.tgz",
"integrity": "sha512-sP2ru2v0P290WFfv49Ap8MF6PkzGNnGlAwHweB4WR4mr5d2d0woiCluUeJ218w7/+PmoBy9JmYgD5A4mLcWOFA==",
"requires": {
"is-docker": "^2.0.0",
"is-wsl": "^2.1.1"
@ -10063,9 +10063,9 @@
}
},
"ws": {
"version": "7.2.1",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.1.tgz",
"integrity": "sha512-sucePNSafamSKoOqoNfBd8V0StlkzJKL2ZAhGQinCfNQ+oacw+Pk7lcdAElecBF2VkLNZRiIb5Oi1Q5lVUVt2A=="
"version": "7.2.3",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.3.tgz",
"integrity": "sha512-HTDl9G9hbkNDk98naoR/cHDws7+EyYMOdL1BmjsZXRUjf7d+MficC4B7HLUPlSiho0vg+CWKrGIt/VJBd1xunQ=="
},
"x-xss-protection": {
"version": "1.3.0",

View File

@ -27,7 +27,7 @@
"commonmark": "0.29.1",
"cookie-parser": "1.4.4",
"csurf": "1.11.0",
"dayjs": "1.8.21",
"dayjs": "1.8.22",
"debug": "4.1.1",
"ejs": "2.7.4",
"electron-debug": "3.0.1",
@ -53,7 +53,7 @@
"mime-types": "2.1.26",
"multer": "1.4.2",
"node-abi": "2.15.0",
"open": "7.0.2",
"open": "7.0.3",
"portscanner": "2.2.0",
"rand-token": "0.4.0",
"rcedit": "2.1.0",
@ -71,7 +71,7 @@
"turndown": "5.0.3",
"turndown-plugin-gfm": "1.0.2",
"unescape": "1.0.1",
"ws": "7.2.1"
"ws": "7.2.3"
},
"devDependencies": {
"electron": "9.0.0-beta.7",

View File

@ -44,7 +44,7 @@ const auth = require('../services/auth');
const cls = require('../services/cls');
const sql = require('../services/sql');
const protectedSessionService = require('../services/protected_session');
const syncService = require('../services/sync');
const syncTableService = require('../services/sync_table');
const csurf = require('csurf');
const csrfMiddleware = csurf({
@ -53,7 +53,7 @@ const csrfMiddleware = csurf({
});
function apiResultHandler(req, res, result) {
res.setHeader('trilium-max-sync-id', syncService.getMaxSyncId());
res.setHeader('trilium-max-sync-id', syncTableService.getMaxSyncId());
// if it's an array and first element is integer then we consider this to be [statusCode, response] format
if (Array.isArray(result) && result.length > 0 && Number.isInteger(result[0])) {

View File

@ -8,6 +8,8 @@ const dateUtils = require('./date_utils');
const log = require('./log');
const cls = require('./cls');
let maxSyncId = 0;
async function insertEntitySync(entityName, entityId, sourceId, isSynced) {
const sync = {
entityName: entityName,
@ -19,6 +21,8 @@ async function insertEntitySync(entityName, entityId, sourceId, isSynced) {
sync.id = await sql.replace("sync", sync);
maxSyncId = Math.max(maxSyncId, sync.id);
return sync;
}
@ -115,5 +119,6 @@ module.exports = {
addApiTokenSync: async (apiTokenId, sourceId) => await addEntitySync("api_tokens", apiTokenId, sourceId),
addEntitySync,
fillAllSyncRows,
addEntitySyncsForSector
addEntitySyncsForSector,
getMaxSyncId: () => maxSyncId
};