mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
sync are sent upon DB commit
This commit is contained in:
parent
05b51c0f68
commit
eeedb91ef7
@ -12,6 +12,8 @@ export class LoadResults {
|
|||||||
this.noteReorderings = [];
|
this.noteReorderings = [];
|
||||||
|
|
||||||
this.noteRevisions = [];
|
this.noteRevisions = [];
|
||||||
|
|
||||||
|
this.contentNoteIdToSourceId = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
addNote(noteId, sourceId) {
|
addNote(noteId, sourceId) {
|
||||||
@ -76,4 +78,16 @@ export class LoadResults {
|
|||||||
const sourceIds = this.noteIdToSourceId[noteId];
|
const sourceIds = this.noteIdToSourceId[noteId];
|
||||||
return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
|
return sourceIds && !!sourceIds.find(sId => sId !== sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
addNoteContent(noteId, sourceId) {
|
||||||
|
this.contentNoteIdToSourceId.push({noteId, sourceId});
|
||||||
|
}
|
||||||
|
|
||||||
|
isNoteContentReloaded(noteId, sourceId) {
|
||||||
|
if (!noteId) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.contentNoteIdToSourceId.find(l => l.noteId === noteId && l.sourceId !== sourceId);
|
||||||
|
}
|
||||||
}
|
}
|
@ -328,7 +328,10 @@ class TreeCache {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// missing reloading the relation target note
|
syncRows.filter(sync => sync.entityName === 'note_contents').forEach(sync => {
|
||||||
|
loadResults.addNoteContent(sync.entityId, sync.sourceId);
|
||||||
|
});
|
||||||
|
|
||||||
syncRows.filter(sync => sync.entityName === 'note_revisions').forEach(sync => {
|
syncRows.filter(sync => sync.entityName === 'note_revisions').forEach(sync => {
|
||||||
loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId);
|
loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId);
|
||||||
});
|
});
|
||||||
|
@ -4,6 +4,7 @@ import protectedSessionHolder from "../services/protected_session_holder.js";
|
|||||||
import SpacedUpdate from "../services/spaced_update.js";
|
import SpacedUpdate from "../services/spaced_update.js";
|
||||||
import server from "../services/server.js";
|
import server from "../services/server.js";
|
||||||
import libraryLoader from "../services/library_loader.js";
|
import libraryLoader from "../services/library_loader.js";
|
||||||
|
import noteDetailService from "../services/note_detail.js";
|
||||||
|
|
||||||
const TPL = `
|
const TPL = `
|
||||||
<div class="note-detail">
|
<div class="note-detail">
|
||||||
@ -220,8 +221,12 @@ export default class NoteDetailWidget extends TabAwareWidget {
|
|||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
entitiesReloadedListener({loadResults}) {
|
async entitiesReloadedListener({loadResults}) {
|
||||||
if (loadResults.isNoteReloaded(this.noteId, this.componentId)) {
|
if (loadResults.isNoteContentReloaded(this.noteId, this.componentId)) {
|
||||||
|
this.tabContext.noteFull = await noteDetailService.loadNoteFull(this.noteId);
|
||||||
|
|
||||||
|
console.log("Reloaded", this.tabContext.noteFull);
|
||||||
|
|
||||||
this.refreshWithNote(this.note, this.notePath);
|
this.refreshWithNote(this.note, this.notePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import * as syncService from "../services/sync.js";
|
||||||
|
|
||||||
const setupRoute = require('./setup');
|
const setupRoute = require('./setup');
|
||||||
const loginRoute = require('./login');
|
const loginRoute = require('./login');
|
||||||
const indexRoute = require('./index');
|
const indexRoute = require('./index');
|
||||||
@ -53,7 +55,7 @@ const csrfMiddleware = csurf({
|
|||||||
});
|
});
|
||||||
|
|
||||||
function apiResultHandler(req, res, result) {
|
function apiResultHandler(req, res, result) {
|
||||||
res.setHeader('trilium-max-sync-id', syncTableService.getMaxSyncId());
|
res.setHeader('trilium-max-sync-id', syncService.getMaxSyncId());
|
||||||
|
|
||||||
// if it's an array and first element is integer then we consider this to be [statusCode, response] format
|
// 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])) {
|
if (Array.isArray(result) && result.length > 0 && Number.isInteger(result[0])) {
|
||||||
|
@ -21,6 +21,18 @@ function isEntityEventsDisabled() {
|
|||||||
return !!namespace.get('disableEntityEvents');
|
return !!namespace.get('disableEntityEvents');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getSyncRows() {
|
||||||
|
return namespace.get('syncRows') || [];
|
||||||
|
}
|
||||||
|
|
||||||
|
function addSyncRow(syncRow) {
|
||||||
|
const syncRows = getSyncRows();
|
||||||
|
|
||||||
|
syncRows.push(syncRow);
|
||||||
|
|
||||||
|
namespace.set('syncRows', syncRows);
|
||||||
|
}
|
||||||
|
|
||||||
function reset() {
|
function reset() {
|
||||||
clsHooked.reset();
|
clsHooked.reset();
|
||||||
}
|
}
|
||||||
@ -32,5 +44,7 @@ module.exports = {
|
|||||||
getSourceId,
|
getSourceId,
|
||||||
disableEntityEvents,
|
disableEntityEvents,
|
||||||
isEntityEventsDisabled,
|
isEntityEventsDisabled,
|
||||||
reset
|
reset,
|
||||||
|
getSyncRows,
|
||||||
|
addSyncRow
|
||||||
};
|
};
|
@ -207,6 +207,8 @@ async function transactional(func) {
|
|||||||
|
|
||||||
await commit();
|
await commit();
|
||||||
|
|
||||||
|
require('./ws.js').sendPingToAllClients();
|
||||||
|
|
||||||
transactionActive = false;
|
transactionActive = false;
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@ const dateUtils = require('./date_utils');
|
|||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
|
|
||||||
let syncs = [];
|
|
||||||
|
|
||||||
async function insertEntitySync(entityName, entityId, sourceId) {
|
async function insertEntitySync(entityName, entityId, sourceId) {
|
||||||
const sync = {
|
const sync = {
|
||||||
entityName: entityName,
|
entityName: entityName,
|
||||||
@ -22,9 +20,7 @@ async function insertEntitySync(entityName, entityId, sourceId) {
|
|||||||
async function addEntitySync(entityName, entityId, sourceId) {
|
async function addEntitySync(entityName, entityId, sourceId) {
|
||||||
const sync = await insertEntitySync(entityName, entityId, sourceId);
|
const sync = await insertEntitySync(entityName, entityId, sourceId);
|
||||||
|
|
||||||
syncs.push(sync);
|
cls.addSyncRow(sync);
|
||||||
|
|
||||||
setTimeout(() => require('./ws').sendPingToAllClients(), 50);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function addEntitySyncsForSector(entityName, entityPrimaryKey, sector) {
|
async function addEntitySyncsForSector(entityName, entityPrimaryKey, sector) {
|
||||||
@ -35,14 +31,6 @@ async function addEntitySyncsForSector(entityName, entityPrimaryKey, sector) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMaxSyncId() {
|
|
||||||
return syncs.length === 0 ? 0 : syncs[syncs.length - 1].id;
|
|
||||||
}
|
|
||||||
|
|
||||||
function getEntitySyncsNewerThan(syncId) {
|
|
||||||
return syncs.filter(s => s.id > syncId);
|
|
||||||
}
|
|
||||||
|
|
||||||
async function cleanupSyncRowsForMissingEntities(entityName, entityPrimaryKey) {
|
async function cleanupSyncRowsForMissingEntities(entityName, entityPrimaryKey) {
|
||||||
await sql.execute(`
|
await sql.execute(`
|
||||||
DELETE
|
DELETE
|
||||||
@ -114,7 +102,5 @@ module.exports = {
|
|||||||
addApiTokenSync: async (apiTokenId, sourceId) => await addEntitySync("api_tokens", apiTokenId, sourceId),
|
addApiTokenSync: async (apiTokenId, sourceId) => await addEntitySync("api_tokens", apiTokenId, sourceId),
|
||||||
addEntitySync,
|
addEntitySync,
|
||||||
fillAllSyncRows,
|
fillAllSyncRows,
|
||||||
getEntitySyncsNewerThan,
|
|
||||||
getMaxSyncId,
|
|
||||||
addEntitySyncsForSector
|
addEntitySyncsForSector
|
||||||
};
|
};
|
@ -2,6 +2,7 @@ const WebSocket = require('ws');
|
|||||||
const utils = require('./utils');
|
const utils = require('./utils');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
|
const cls = require('./cls');
|
||||||
const syncMutexService = require('./sync_mutex');
|
const syncMutexService = require('./sync_mutex');
|
||||||
|
|
||||||
let webSocketServer;
|
let webSocketServer;
|
||||||
@ -89,11 +90,10 @@ async function fillInAdditionalProperties(sync) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function sendPing(client) {
|
async function sendPing(client) {
|
||||||
const syncData = require('./sync_table')
|
const syncRows = cls.getSyncRows()
|
||||||
.getEntitySyncsNewerThan(lastAcceptedSyncIds[client.id])
|
|
||||||
.filter(r => r.entityName !== 'recent_notes'); // only noise ...
|
.filter(r => r.entityName !== 'recent_notes'); // only noise ...
|
||||||
|
|
||||||
for (const sync of syncData) {
|
for (const sync of syncRows) {
|
||||||
try {
|
try {
|
||||||
await fillInAdditionalProperties(sync);
|
await fillInAdditionalProperties(sync);
|
||||||
}
|
}
|
||||||
@ -107,7 +107,7 @@ async function sendPing(client) {
|
|||||||
|
|
||||||
sendMessage(client, {
|
sendMessage(client, {
|
||||||
type: 'sync',
|
type: 'sync',
|
||||||
data: syncData,
|
data: syncRows,
|
||||||
outstandingSyncs: stats.outstandingPushes + stats.outstandingPulls
|
outstandingSyncs: stats.outstandingPushes + stats.outstandingPulls
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user