mirror of
https://github.com/zadam/trilium.git
synced 2025-11-10 07:15:51 +01:00
sync fixes
This commit is contained in:
@@ -15,6 +15,12 @@ function putEntityChangeWithInstanceId(origEntityChange, instanceId) {
|
||||
putEntityChange(ec);
|
||||
}
|
||||
|
||||
function putEntityChangeWithForcedChange(origEntityChange) {
|
||||
const ec = {...origEntityChange, changeId: null};
|
||||
|
||||
putEntityChange(ec);
|
||||
}
|
||||
|
||||
function putEntityChange(origEntityChange) {
|
||||
const ec = {...origEntityChange};
|
||||
|
||||
@@ -66,13 +72,37 @@ function putEntityChangeForOtherInstances(ec) {
|
||||
function addEntityChangesForSector(entityName, sector) {
|
||||
const entityChanges = sql.getRows(`SELECT * FROM entity_changes WHERE entityName = ? AND SUBSTR(entityId, 1, 1) = ?`, [entityName, sector]);
|
||||
|
||||
let entitiesInserted = entityChanges.length;
|
||||
|
||||
sql.transactional(() => {
|
||||
if (entityName === 'blobs') {
|
||||
entitiesInserted += addEntityChangesForDependingEntity(sector, 'notes', 'noteId');
|
||||
entitiesInserted += addEntityChangesForDependingEntity(sector, 'attachments', 'attachmentId');
|
||||
entitiesInserted += addEntityChangesForDependingEntity(sector, 'revisions', 'revisionId');
|
||||
}
|
||||
|
||||
for (const ec of entityChanges) {
|
||||
putEntityChange(ec);
|
||||
putEntityChangeWithForcedChange(ec);
|
||||
}
|
||||
});
|
||||
|
||||
log.info(`Added sector ${sector} of '${entityName}' (${entityChanges.length} entities) to the sync queue.`);
|
||||
log.info(`Added sector ${sector} of '${entityName}' (${entitiesInserted} entities) to the sync queue.`);
|
||||
}
|
||||
|
||||
function addEntityChangesForDependingEntity(sector, tableName, primaryKeyColumn) {
|
||||
// problem in blobs might be caused by problem in entity referencing the blob
|
||||
const dependingEntityChanges = sql.getRows(`
|
||||
SELECT dep_change.*
|
||||
FROM entity_changes orig_sector
|
||||
JOIN ${tableName} ON ${tableName}.blobId = orig_sector.entityId
|
||||
JOIN entity_changes dep_change ON dep_change.entityName = '${tableName}' AND dep_change.entityId = ${tableName}.${primaryKeyColumn}
|
||||
WHERE orig_sector.entityName = 'blobs' AND SUBSTR(orig_sector.entityId, 1, 1) = ?`, [sector]);
|
||||
|
||||
for (const ec of dependingEntityChanges) {
|
||||
putEntityChangeWithForcedChange(ec);
|
||||
}
|
||||
|
||||
return dependingEntityChanges.length;
|
||||
}
|
||||
|
||||
function cleanupEntityChangesForMissingEntities(entityName, entityPrimaryKey) {
|
||||
@@ -161,6 +191,7 @@ function recalculateMaxEntityChangeId() {
|
||||
module.exports = {
|
||||
putNoteReorderingEntityChange,
|
||||
putEntityChangeForOtherInstances,
|
||||
putEntityChangeWithForcedChange,
|
||||
putEntityChange,
|
||||
putEntityChangeWithInstanceId,
|
||||
fillAllEntityChanges,
|
||||
|
||||
Reference in New Issue
Block a user