mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
fixed syncing of erased notes, closes #2316
This commit is contained in:
parent
600c16551a
commit
df0411197b
@ -160,6 +160,11 @@ if (utils.isElectron()) {
|
|||||||
arg.body = JSON.parse(arg.body);
|
arg.body = JSON.parse(arg.body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!(arg.requestId in reqResolves)) {
|
||||||
|
// this can happen when reload happens between firing up the request and receiving the response
|
||||||
|
throw new Error(`Unknown requestId="${arg.requestId}"`);
|
||||||
|
}
|
||||||
|
|
||||||
reqResolves[arg.requestId]({
|
reqResolves[arg.requestId]({
|
||||||
body: arg.body,
|
body: arg.body,
|
||||||
headers: arg.headers
|
headers: arg.headers
|
||||||
|
@ -705,7 +705,7 @@ sqlInit.dbReady.then(() => {
|
|||||||
setInterval(cls.wrap(runPeriodicChecks), 60 * 60 * 1000);
|
setInterval(cls.wrap(runPeriodicChecks), 60 * 60 * 1000);
|
||||||
|
|
||||||
// kickoff checks soon after startup (to not block the initial load)
|
// kickoff checks soon after startup (to not block the initial load)
|
||||||
setTimeout(cls.wrap(runPeriodicChecks), 10 * 1000);
|
setTimeout(cls.wrap(runPeriodicChecks), 4 * 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
@ -679,10 +679,10 @@ function eraseNotes(noteIdsToErase) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sql.executeMany(`DELETE FROM notes WHERE noteId IN (???)`, noteIdsToErase);
|
sql.executeMany(`DELETE FROM notes WHERE noteId IN (???)`, noteIdsToErase);
|
||||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'notes' AND entityId IN (???)`, noteIdsToErase);
|
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'notes' AND entityId IN (???)`, noteIdsToErase));
|
||||||
|
|
||||||
sql.executeMany(`DELETE FROM note_contents WHERE noteId IN (???)`, noteIdsToErase);
|
sql.executeMany(`DELETE FROM note_contents WHERE noteId IN (???)`, noteIdsToErase);
|
||||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'note_contents' AND entityId IN (???)`, noteIdsToErase);
|
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'note_contents' AND entityId IN (???)`, noteIdsToErase));
|
||||||
|
|
||||||
// we also need to erase all "dependent" entities of the erased notes
|
// we also need to erase all "dependent" entities of the erased notes
|
||||||
const branchIdsToErase = sql.getManyRows(`SELECT branchId FROM branches WHERE noteId IN (???)`, noteIdsToErase)
|
const branchIdsToErase = sql.getManyRows(`SELECT branchId FROM branches WHERE noteId IN (???)`, noteIdsToErase)
|
||||||
@ -703,6 +703,14 @@ function eraseNotes(noteIdsToErase) {
|
|||||||
log.info(`Erased notes: ${JSON.stringify(noteIdsToErase)}`);
|
log.info(`Erased notes: ${JSON.stringify(noteIdsToErase)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function setEntityChangesAsErased(entityChanges) {
|
||||||
|
for (const ec of entityChanges) {
|
||||||
|
ec.isErased = true;
|
||||||
|
|
||||||
|
entityChangesService.addEntityChange(ec);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function eraseBranches(branchIdsToErase) {
|
function eraseBranches(branchIdsToErase) {
|
||||||
if (branchIdsToErase.length === 0) {
|
if (branchIdsToErase.length === 0) {
|
||||||
return;
|
return;
|
||||||
@ -710,7 +718,7 @@ function eraseBranches(branchIdsToErase) {
|
|||||||
|
|
||||||
sql.executeMany(`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase);
|
sql.executeMany(`DELETE FROM branches WHERE branchId IN (???)`, branchIdsToErase);
|
||||||
|
|
||||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'branches' AND entityId IN (???)`, branchIdsToErase);
|
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'branches' AND entityId IN (???)`, branchIdsToErase));
|
||||||
}
|
}
|
||||||
|
|
||||||
function eraseAttributes(attributeIdsToErase) {
|
function eraseAttributes(attributeIdsToErase) {
|
||||||
@ -720,7 +728,7 @@ function eraseAttributes(attributeIdsToErase) {
|
|||||||
|
|
||||||
sql.executeMany(`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase);
|
sql.executeMany(`DELETE FROM attributes WHERE attributeId IN (???)`, attributeIdsToErase);
|
||||||
|
|
||||||
sql.executeMany(`UPDATE entity_changes SET isErased = 1 WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase);
|
setEntityChangesAsErased(sql.getManyRows(`SELECT * FROM entity_changes WHERE entityName = 'attributes' AND entityId IN (???)`, attributeIdsToErase));
|
||||||
}
|
}
|
||||||
|
|
||||||
function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) {
|
function eraseDeletedEntities(eraseEntitiesAfterTimeInSeconds = null) {
|
||||||
|
@ -395,8 +395,8 @@ function getOutstandingPullCount() {
|
|||||||
require("../becca/becca_loader").beccaLoaded.then(() => {
|
require("../becca/becca_loader").beccaLoaded.then(() => {
|
||||||
setInterval(cls.wrap(sync), 60000);
|
setInterval(cls.wrap(sync), 60000);
|
||||||
|
|
||||||
// kickoff initial sync immediately
|
// kickoff initial sync immediately, but should happen after initial consistency checks
|
||||||
setTimeout(cls.wrap(sync), 2000);
|
setTimeout(cls.wrap(sync), 5000);
|
||||||
|
|
||||||
// called just so ws.setLastSyncedPush() is called
|
// called just so ws.setLastSyncedPush() is called
|
||||||
getLastSyncedPush();
|
getLastSyncedPush();
|
||||||
|
@ -9,7 +9,7 @@ function updateEntity(entityChange, entityRow) {
|
|||||||
if (!entityRow) {
|
if (!entityRow) {
|
||||||
if (entityChange.isSynced) {
|
if (entityChange.isSynced) {
|
||||||
if (entityChange.isErased) {
|
if (entityChange.isErased) {
|
||||||
entityChangesService.addEntityChange(entityChange, true);
|
eraseEntity(entityChange);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
log.info(`Encountered synced non-erased entity change without entity: ${JSON.stringify(entityChange)}`);
|
log.info(`Encountered synced non-erased entity change without entity: ${JSON.stringify(entityChange)}`);
|
||||||
@ -105,6 +105,23 @@ function handleContent(content) {
|
|||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function eraseEntity(entityChange) {
|
||||||
|
const {entityName, entityId} = entityChange;
|
||||||
|
|
||||||
|
if (!["notes", "note_contents", "branches", "attributes", "note_revisions", "note_revision_contents"].includes(entityName)) {
|
||||||
|
log.error(`Cannot erase entity ${entityName}, id ${entityId}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const keyName = entityConstructor.getEntityFromEntityName(entityName).primaryKeyName;
|
||||||
|
|
||||||
|
sql.execute(`DELETE FROM ${entityName} WHERE ${keyName} = ?`, [entityId]);
|
||||||
|
|
||||||
|
eventService.emit(eventService.ENTITY_DELETE_SYNCED, { entityName, entityId });
|
||||||
|
|
||||||
|
entityChangesService.addEntityChange(entityChange, true);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
updateEntity
|
updateEntity
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user