mirror of
https://github.com/zadam/trilium.git
synced 2025-11-14 09:15:50 +01:00
refactored "sync" table to "entity_changes"
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
const sql = require('../../services/sql');
|
||||
const utils = require('../../services/utils');
|
||||
const syncTableService = require('../../services/sync_table');
|
||||
const entityChangesService = require('../../services/entity_changes.js');
|
||||
const treeService = require('../../services/tree');
|
||||
const noteService = require('../../services/notes');
|
||||
const repository = require('../../services/repository');
|
||||
@@ -66,7 +66,7 @@ function moveBranchBeforeNote(req) {
|
||||
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition >= ? AND isDeleted = 0",
|
||||
[beforeNote.parentNoteId, beforeNote.notePosition]);
|
||||
|
||||
syncTableService.addNoteReorderingSync(beforeNote.parentNoteId);
|
||||
entityChangesService.addNoteReorderingSync(beforeNote.parentNoteId);
|
||||
|
||||
if (branchToMove.parentNoteId === beforeNote.parentNoteId) {
|
||||
branchToMove.notePosition = beforeNote.notePosition;
|
||||
@@ -100,7 +100,7 @@ function moveBranchAfterNote(req) {
|
||||
sql.execute("UPDATE branches SET notePosition = notePosition + 10 WHERE parentNoteId = ? AND notePosition > ? AND isDeleted = 0",
|
||||
[afterNote.parentNoteId, afterNote.notePosition]);
|
||||
|
||||
syncTableService.addNoteReorderingSync(afterNote.parentNoteId);
|
||||
entityChangesService.addNoteReorderingSync(afterNote.parentNoteId);
|
||||
|
||||
const movedNotePosition = afterNote.notePosition + 10;
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ function loginSync(req) {
|
||||
|
||||
return {
|
||||
sourceId: sourceIdService.getCurrentSourceId(),
|
||||
maxSyncId: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1")
|
||||
maxEntityChangeId: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1")
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ function exec(req) {
|
||||
return {
|
||||
success: true,
|
||||
executionResult: result,
|
||||
maxSyncId: syncService.getMaxSyncId()
|
||||
maxEntityChangeId: syncService.getMaxEntityChangeId()
|
||||
};
|
||||
}
|
||||
catch (e) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
const syncService = require('../../services/sync');
|
||||
const syncUpdateService = require('../../services/sync_update');
|
||||
const syncTableService = require('../../services/sync_table');
|
||||
const entityChangesService = require('../../services/entity_changes.js');
|
||||
const sql = require('../../services/sql');
|
||||
const sqlInit = require('../../services/sql_init');
|
||||
const optionService = require('../../services/options');
|
||||
@@ -50,7 +50,7 @@ function getStats() {
|
||||
function checkSync() {
|
||||
return {
|
||||
entityHashes: contentHashService.getEntityHashes(),
|
||||
maxSyncId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1')
|
||||
maxEntityChangeId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1')
|
||||
};
|
||||
}
|
||||
|
||||
@@ -60,8 +60,8 @@ function syncNow() {
|
||||
return syncService.sync();
|
||||
}
|
||||
|
||||
function fillSyncRows() {
|
||||
syncTableService.fillAllSyncRows();
|
||||
function fillEntityChanges() {
|
||||
entityChangesService.fillAllEntityChanges();
|
||||
|
||||
log.info("Sync rows have been filled.");
|
||||
}
|
||||
@@ -82,32 +82,32 @@ function forceNoteSync(req) {
|
||||
const now = dateUtils.utcNowDateTime();
|
||||
|
||||
sql.execute(`UPDATE notes SET utcDateModified = ? WHERE noteId = ?`, [now, noteId]);
|
||||
syncTableService.addNoteSync(noteId);
|
||||
entityChangesService.addNoteSync(noteId);
|
||||
|
||||
sql.execute(`UPDATE note_contents SET utcDateModified = ? WHERE noteId = ?`, [now, noteId]);
|
||||
syncTableService.addNoteContentSync(noteId);
|
||||
entityChangesService.addNoteContentSync(noteId);
|
||||
|
||||
for (const branchId of sql.getColumn("SELECT branchId FROM branches WHERE noteId = ?", [noteId])) {
|
||||
sql.execute(`UPDATE branches SET utcDateModified = ? WHERE branchId = ?`, [now, branchId]);
|
||||
|
||||
syncTableService.addBranchSync(branchId);
|
||||
entityChangesService.addBranchSync(branchId);
|
||||
}
|
||||
|
||||
for (const attributeId of sql.getColumn("SELECT attributeId FROM attributes WHERE noteId = ?", [noteId])) {
|
||||
sql.execute(`UPDATE attributes SET utcDateModified = ? WHERE attributeId = ?`, [now, attributeId]);
|
||||
|
||||
syncTableService.addAttributeSync(attributeId);
|
||||
entityChangesService.addAttributeSync(attributeId);
|
||||
}
|
||||
|
||||
for (const noteRevisionId of sql.getColumn("SELECT noteRevisionId FROM note_revisions WHERE noteId = ?", [noteId])) {
|
||||
sql.execute(`UPDATE note_revisions SET utcDateModified = ? WHERE noteRevisionId = ?`, [now, noteRevisionId]);
|
||||
syncTableService.addNoteRevisionSync(noteRevisionId);
|
||||
entityChangesService.addNoteRevisionSync(noteRevisionId);
|
||||
|
||||
sql.execute(`UPDATE note_revision_contents SET utcDateModified = ? WHERE noteRevisionId = ?`, [now, noteRevisionId]);
|
||||
syncTableService.addNoteRevisionContentSync(noteRevisionId);
|
||||
entityChangesService.addNoteRevisionContentSync(noteRevisionId);
|
||||
}
|
||||
|
||||
syncTableService.addRecentNoteSync(noteId);
|
||||
entityChangesService.addRecentNoteSync(noteId);
|
||||
|
||||
log.info("Forcing note sync for " + noteId);
|
||||
|
||||
@@ -118,17 +118,17 @@ function forceNoteSync(req) {
|
||||
function getChanged(req) {
|
||||
const startTime = Date.now();
|
||||
|
||||
const lastSyncId = parseInt(req.query.lastSyncId);
|
||||
const lastEntityChangeId = parseInt(req.query.lastEntityChangedId);
|
||||
|
||||
const syncs = sql.getRows("SELECT * FROM sync WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastSyncId]);
|
||||
const entityChanges = sql.getRows("SELECT * FROM entity_changes WHERE isSynced = 1 AND id > ? LIMIT 1000", [lastEntityChangeId]);
|
||||
|
||||
const ret = {
|
||||
syncs: syncService.getSyncRecords(syncs),
|
||||
maxSyncId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM sync WHERE isSynced = 1')
|
||||
syncs: syncService.getEntityChangesRecords(entityChanges),
|
||||
maxEntityChangeId: sql.getValue('SELECT COALESCE(MAX(id), 0) FROM entity_changes WHERE isSynced = 1')
|
||||
};
|
||||
|
||||
if (ret.syncs.length > 0) {
|
||||
log.info(`Returning ${ret.syncs.length} sync records in ${Date.now() - startTime}ms`);
|
||||
log.info(`Returning ${ret.syncs.length} entity changes in ${Date.now() - startTime}ms`);
|
||||
}
|
||||
|
||||
return ret;
|
||||
@@ -155,14 +155,14 @@ function queueSector(req) {
|
||||
|
||||
const entityPrimaryKey = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName;
|
||||
|
||||
syncTableService.addEntitySyncsForSector(entityName, entityPrimaryKey, sector);
|
||||
entityChangesService.addEntityChangesForSector(entityName, entityPrimaryKey, sector);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
testSync,
|
||||
checkSync,
|
||||
syncNow,
|
||||
fillSyncRows,
|
||||
fillEntityChanges,
|
||||
forceFullSync,
|
||||
forceNoteSync,
|
||||
getChanged,
|
||||
|
||||
@@ -23,7 +23,7 @@ function index(req, res) {
|
||||
treeFontSize: parseInt(options.treeFontSize),
|
||||
detailFontSize: parseInt(options.detailFontSize),
|
||||
sourceId: sourceIdService.generateSourceId(),
|
||||
maxSyncIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM sync"),
|
||||
maxEntityChangeIdAtLoad: sql.getValue("SELECT COALESCE(MAX(id), 0) FROM entity_changes"),
|
||||
instanceName: config.General ? config.General.instanceName : null,
|
||||
appCssNoteIds: getAppCssNoteIds(),
|
||||
isDev: env.isDev(),
|
||||
|
||||
@@ -45,7 +45,7 @@ const auth = require('../services/auth');
|
||||
const cls = require('../services/cls');
|
||||
const sql = require('../services/sql');
|
||||
const protectedSessionService = require('../services/protected_session');
|
||||
const syncTableService = require('../services/sync_table');
|
||||
const entityChangesService = require('../services/entity_changes.js');
|
||||
const csurf = require('csurf');
|
||||
|
||||
const csrfMiddleware = csurf({
|
||||
@@ -54,7 +54,7 @@ const csrfMiddleware = csurf({
|
||||
});
|
||||
|
||||
function apiResultHandler(req, res, result) {
|
||||
res.setHeader('trilium-max-sync-id', syncTableService.getMaxSyncId());
|
||||
res.setHeader('trilium-max-entity-change-id', entityChangesService.getMaxEntityChangeId());
|
||||
|
||||
// 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])) {
|
||||
@@ -205,7 +205,7 @@ function register(app) {
|
||||
|
||||
apiRoute(POST, '/api/sync/test', syncApiRoute.testSync);
|
||||
apiRoute(POST, '/api/sync/now', syncApiRoute.syncNow);
|
||||
apiRoute(POST, '/api/sync/fill-sync-rows', syncApiRoute.fillSyncRows);
|
||||
apiRoute(POST, '/api/sync/fill-sync-rows', syncApiRoute.fillEntityChanges);
|
||||
apiRoute(POST, '/api/sync/force-full-sync', syncApiRoute.forceFullSync);
|
||||
apiRoute(POST, '/api/sync/force-note-sync/:noteId', syncApiRoute.forceNoteSync);
|
||||
route(GET, '/api/sync/check', [auth.checkApiAuth], syncApiRoute.checkSync, apiResultHandler);
|
||||
|
||||
Reference in New Issue
Block a user