mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
renamed remnants of "sync" to "entity_change"
This commit is contained in:
parent
cdc2721ac1
commit
1cc7917b6e
@ -144,7 +144,7 @@ async function consumeSyncData() {
|
|||||||
const allEntityChanges = syncDataQueue;
|
const allEntityChanges = syncDataQueue;
|
||||||
syncDataQueue = [];
|
syncDataQueue = [];
|
||||||
|
|
||||||
const nonProcessedEntityChanges = allEntityChanges.filter(sync => !processedEntityChangeIds.has(sync.id));
|
const nonProcessedEntityChanges = allEntityChanges.filter(ec => !processedEntityChangeIds.has(ec.id));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await utils.timeLimit(processEntityChanges(nonProcessedEntityChanges), 30000);
|
await utils.timeLimit(processEntityChanges(nonProcessedEntityChanges), 30000);
|
||||||
@ -251,33 +251,33 @@ async function processEntityChanges(entityChanges) {
|
|||||||
|
|
||||||
const loadResults = new LoadResults(treeCache);
|
const loadResults = new LoadResults(treeCache);
|
||||||
|
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'notes')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'notes')) {
|
||||||
const note = treeCache.notes[sync.entityId];
|
const note = treeCache.notes[ec.entityId];
|
||||||
|
|
||||||
if (note) {
|
if (note) {
|
||||||
note.update(sync.entity);
|
note.update(ec.entity);
|
||||||
loadResults.addNote(sync.entityId, sync.sourceId);
|
loadResults.addNote(ec.entityId, ec.sourceId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'branches')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'branches')) {
|
||||||
let branch = treeCache.branches[sync.entityId];
|
let branch = treeCache.branches[ec.entityId];
|
||||||
const childNote = treeCache.notes[sync.entity.noteId];
|
const childNote = treeCache.notes[ec.entity.noteId];
|
||||||
const parentNote = treeCache.notes[sync.entity.parentNoteId];
|
const parentNote = treeCache.notes[ec.entity.parentNoteId];
|
||||||
|
|
||||||
if (branch) {
|
if (branch) {
|
||||||
branch.update(sync.entity);
|
branch.update(ec.entity);
|
||||||
loadResults.addBranch(sync.entityId, sync.sourceId);
|
loadResults.addBranch(ec.entityId, ec.sourceId);
|
||||||
|
|
||||||
if (sync.entity.isDeleted) {
|
if (ec.entity.isDeleted) {
|
||||||
if (childNote) {
|
if (childNote) {
|
||||||
childNote.parents = childNote.parents.filter(parentNoteId => parentNoteId !== sync.entity.parentNoteId);
|
childNote.parents = childNote.parents.filter(parentNoteId => parentNoteId !== ec.entity.parentNoteId);
|
||||||
delete childNote.parentToBranch[sync.entity.parentNoteId];
|
delete childNote.parentToBranch[ec.entity.parentNoteId];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parentNote) {
|
if (parentNote) {
|
||||||
parentNote.children = parentNote.children.filter(childNoteId => childNoteId !== sync.entity.noteId);
|
parentNote.children = parentNote.children.filter(childNoteId => childNoteId !== ec.entity.noteId);
|
||||||
delete parentNote.childToBranch[sync.entity.noteId];
|
delete parentNote.childToBranch[ec.entity.noteId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -290,12 +290,12 @@ async function processEntityChanges(entityChanges) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!sync.entity.isDeleted) {
|
else if (!ec.entity.isDeleted) {
|
||||||
if (childNote || parentNote) {
|
if (childNote || parentNote) {
|
||||||
branch = new Branch(treeCache, sync.entity);
|
branch = new Branch(treeCache, ec.entity);
|
||||||
treeCache.branches[branch.branchId] = branch;
|
treeCache.branches[branch.branchId] = branch;
|
||||||
|
|
||||||
loadResults.addBranch(sync.entityId, sync.sourceId);
|
loadResults.addBranch(ec.entityId, ec.sourceId);
|
||||||
|
|
||||||
if (childNote) {
|
if (childNote) {
|
||||||
childNote.addParent(branch.parentNoteId, branch.branchId);
|
childNote.addParent(branch.parentNoteId, branch.branchId);
|
||||||
@ -308,14 +308,14 @@ async function processEntityChanges(entityChanges) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'note_reordering')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'note_reordering')) {
|
||||||
const parentNoteIdsToSort = new Set();
|
const parentNoteIdsToSort = new Set();
|
||||||
|
|
||||||
for (const branchId in sync.positions) {
|
for (const branchId in ec.positions) {
|
||||||
const branch = treeCache.branches[branchId];
|
const branch = treeCache.branches[branchId];
|
||||||
|
|
||||||
if (branch) {
|
if (branch) {
|
||||||
branch.notePosition = sync.positions[branchId];
|
branch.notePosition = ec.positions[branchId];
|
||||||
|
|
||||||
parentNoteIdsToSort.add(branch.parentNoteId);
|
parentNoteIdsToSort.add(branch.parentNoteId);
|
||||||
}
|
}
|
||||||
@ -329,20 +329,20 @@ async function processEntityChanges(entityChanges) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadResults.addNoteReordering(sync.entityId, sync.sourceId);
|
loadResults.addNoteReordering(ec.entityId, ec.sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// missing reloading the relation target note
|
// missing reloading the relation target note
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'attributes')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'attributes')) {
|
||||||
let attribute = treeCache.attributes[sync.entityId];
|
let attribute = treeCache.attributes[ec.entityId];
|
||||||
const sourceNote = treeCache.notes[sync.entity.noteId];
|
const sourceNote = treeCache.notes[ec.entity.noteId];
|
||||||
const targetNote = sync.entity.type === 'relation' && treeCache.notes[sync.entity.value];
|
const targetNote = ec.entity.type === 'relation' && treeCache.notes[ec.entity.value];
|
||||||
|
|
||||||
if (attribute) {
|
if (attribute) {
|
||||||
attribute.update(sync.entity);
|
attribute.update(ec.entity);
|
||||||
loadResults.addAttribute(sync.entityId, sync.sourceId);
|
loadResults.addAttribute(ec.entityId, ec.sourceId);
|
||||||
|
|
||||||
if (sync.entity.isDeleted) {
|
if (ec.entity.isDeleted) {
|
||||||
if (sourceNote) {
|
if (sourceNote) {
|
||||||
sourceNote.attributes = sourceNote.attributes.filter(attributeId => attributeId !== attribute.attributeId);
|
sourceNote.attributes = sourceNote.attributes.filter(attributeId => attributeId !== attribute.attributeId);
|
||||||
}
|
}
|
||||||
@ -352,13 +352,13 @@ async function processEntityChanges(entityChanges) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!sync.entity.isDeleted) {
|
else if (!ec.entity.isDeleted) {
|
||||||
if (sourceNote || targetNote) {
|
if (sourceNote || targetNote) {
|
||||||
attribute = new Attribute(treeCache, sync.entity);
|
attribute = new Attribute(treeCache, ec.entity);
|
||||||
|
|
||||||
treeCache.attributes[attribute.attributeId] = attribute;
|
treeCache.attributes[attribute.attributeId] = attribute;
|
||||||
|
|
||||||
loadResults.addAttribute(sync.entityId, sync.sourceId);
|
loadResults.addAttribute(ec.entityId, ec.sourceId);
|
||||||
|
|
||||||
if (sourceNote && !sourceNote.attributes.includes(attribute.attributeId)) {
|
if (sourceNote && !sourceNote.attributes.includes(attribute.attributeId)) {
|
||||||
sourceNote.attributes.push(attribute.attributeId);
|
sourceNote.attributes.push(attribute.attributeId);
|
||||||
@ -371,24 +371,24 @@ async function processEntityChanges(entityChanges) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'note_contents')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'note_contents')) {
|
||||||
delete treeCache.noteComplementPromises[sync.entityId];
|
delete treeCache.noteComplementPromises[ec.entityId];
|
||||||
|
|
||||||
loadResults.addNoteContent(sync.entityId, sync.sourceId);
|
loadResults.addNoteContent(ec.entityId, ec.sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'note_revisions')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'note_revisions')) {
|
||||||
loadResults.addNoteRevision(sync.entityId, sync.noteId, sync.sourceId);
|
loadResults.addNoteRevision(ec.entityId, ec.noteId, ec.sourceId);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const sync of entityChanges.filter(sync => sync.entityName === 'options')) {
|
for (const ec of entityChanges.filter(ec => ec.entityName === 'options')) {
|
||||||
if (sync.entity.name === 'openTabs') {
|
if (ec.entity.name === 'openTabs') {
|
||||||
continue; // only noise
|
continue; // only noise
|
||||||
}
|
}
|
||||||
|
|
||||||
options.set(sync.entity.name, sync.entity.value);
|
options.set(ec.entity.name, ec.entity.value);
|
||||||
|
|
||||||
loadResults.addOption(sync.entity.name);
|
loadResults.addOption(ec.entity.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!loadResults.isEmpty()) {
|
if (!loadResults.isEmpty()) {
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
const sql = require('./sql');
|
const sql = require('./sql');
|
||||||
const repository = require('./repository');
|
const repository = require('./repository');
|
||||||
const sourceIdService = require('./source_id');
|
const sourceIdService = require('./source_id');
|
||||||
|
const dateUtils = require('./date_utils');
|
||||||
const log = require('./log');
|
const log = require('./log');
|
||||||
const cls = require('./cls');
|
const cls = require('./cls');
|
||||||
|
|
||||||
@ -63,8 +64,8 @@ function cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey) {
|
|||||||
FROM entity_changes
|
FROM entity_changes
|
||||||
WHERE
|
WHERE
|
||||||
isErased = 0
|
isErased = 0
|
||||||
AND sync.entityName = '${entityName}'
|
AND entityName = '${entityName}'
|
||||||
AND sync.entityId NOT IN (SELECT ${entityPrimaryKey} FROM ${entityName})`);
|
AND entityId NOT IN (SELECT ${entityPrimaryKey} FROM ${entityName})`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {
|
function fillEntityChanges(entityName, entityPrimaryKey, condition = '') {
|
||||||
@ -120,7 +121,13 @@ function fillAllEntityChanges() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
addNoteReorderingEntityChange: (parentNoteId, sourceId) => addEntityChange("note_reordering", parentNoteId, '', sourceId),
|
addNoteReorderingEntityChange: (parentNoteId, sourceId) => addEntityChange({
|
||||||
|
entityName: "note_reordering",
|
||||||
|
entityId: parentNoteId,
|
||||||
|
hash: 'N/A',
|
||||||
|
isErased: false,
|
||||||
|
utcDateChanged: dateUtils.utcNowDateTime()
|
||||||
|
}, sourceId),
|
||||||
moveEntityChangeToTop,
|
moveEntityChangeToTop,
|
||||||
addEntityChange,
|
addEntityChange,
|
||||||
fillAllEntityChanges,
|
fillAllEntityChanges,
|
||||||
|
@ -71,27 +71,27 @@ function sendMessageToAllClients(message) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function fillInAdditionalProperties(sync) {
|
function fillInAdditionalProperties(entityChange) {
|
||||||
// fill in some extra data needed by the frontend
|
// fill in some extra data needed by the frontend
|
||||||
if (sync.entityName === 'attributes') {
|
if (entityChange.entityName === 'attributes') {
|
||||||
sync.entity = sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [sync.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM attributes WHERE attributeId = ?`, [entityChange.entityId]);
|
||||||
} else if (sync.entityName === 'branches') {
|
} else if (entityChange.entityName === 'branches') {
|
||||||
sync.entity = sql.getRow(`SELECT * FROM branches WHERE branchId = ?`, [sync.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM branches WHERE branchId = ?`, [entityChange.entityId]);
|
||||||
} else if (sync.entityName === 'notes') {
|
} else if (entityChange.entityName === 'notes') {
|
||||||
sync.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [sync.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM notes WHERE noteId = ?`, [entityChange.entityId]);
|
||||||
|
|
||||||
if (sync.entity.isProtected) {
|
if (entityChange.entity.isProtected) {
|
||||||
sync.entity.title = protectedSessionService.decryptString(sync.entity.title);
|
entityChange.entity.title = protectedSessionService.decryptString(entityChange.entity.title);
|
||||||
}
|
}
|
||||||
} else if (sync.entityName === 'note_revisions') {
|
} else if (entityChange.entityName === 'note_revisions') {
|
||||||
sync.noteId = sql.getValue(`SELECT noteId
|
entityChange.noteId = sql.getValue(`SELECT noteId
|
||||||
FROM note_revisions
|
FROM note_revisions
|
||||||
WHERE noteRevisionId = ?`, [sync.entityId]);
|
WHERE noteRevisionId = ?`, [entityChange.entityId]);
|
||||||
} else if (sync.entityName === 'note_reordering') {
|
} else if (entityChange.entityName === 'note_reordering') {
|
||||||
sync.positions = sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [sync.entityId]);
|
entityChange.positions = sql.getMap(`SELECT branchId, notePosition FROM branches WHERE isDeleted = 0 AND parentNoteId = ?`, [entityChange.entityId]);
|
||||||
}
|
}
|
||||||
else if (sync.entityName === 'options') {
|
else if (entityChange.entityName === 'options') {
|
||||||
sync.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [sync.entityId]);
|
entityChange.entity = sql.getRow(`SELECT * FROM options WHERE name = ?`, [entityChange.entityId]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user