mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
restore all "named" notes quickly after their deletion, #3517
This commit is contained in:
parent
60602a2264
commit
082caf98e8
@ -4,6 +4,8 @@ const treeService = require('./tree');
|
|||||||
const noteService = require('./notes');
|
const noteService = require('./notes');
|
||||||
const becca = require('../becca/becca');
|
const becca = require('../becca/becca');
|
||||||
const Attribute = require('../becca/entities/attribute');
|
const Attribute = require('../becca/entities/attribute');
|
||||||
|
const hiddenSubtreeService = require("./hidden_subtree");
|
||||||
|
const oneTimeTimer = require("./one_time_timer");
|
||||||
|
|
||||||
function runAttachedRelations(note, relationName, originEntity) {
|
function runAttachedRelations(note, relationName, originEntity) {
|
||||||
if (!note) {
|
if (!note) {
|
||||||
@ -206,6 +208,16 @@ eventService.subscribe(eventService.ENTITY_DELETED, ({ entityName, entity }) =>
|
|||||||
if (entityName === 'branches') {
|
if (entityName === 'branches') {
|
||||||
runAttachedRelations(entity.getNote(), 'runOnBranchDeletion', entity);
|
runAttachedRelations(entity.getNote(), 'runOnBranchDeletion', entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entityName === 'notes' && entity.noteId.startsWith("_")) {
|
||||||
|
// "named" note has been deleted, we will probably need to rebuild the hidden subtree
|
||||||
|
// scheduling so that bulk deletes won't trigger so many checks
|
||||||
|
oneTimeTimer.scheduleExecution('hidden-subtree-check', 1000, () => {
|
||||||
|
console.log("Checking hidden subtree");
|
||||||
|
|
||||||
|
hiddenSubtreeService.checkHiddenSubtree();
|
||||||
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
|
25
src/services/one_time_timer.js
Normal file
25
src/services/one_time_timer.js
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
const scheduledExecutions = {};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subsequent calls will not move the timer to future. The first caller determines the time of execution.
|
||||||
|
*
|
||||||
|
* The good thing about synchronous better-sqlite3 is that this cannot interrupt transaction. The execution will be called
|
||||||
|
* only outside of a transaction.
|
||||||
|
*/
|
||||||
|
function scheduleExecution(name, milliseconds, cb) {
|
||||||
|
if (name in scheduledExecutions) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scheduledExecutions[name] = true;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
delete scheduledExecutions[name];
|
||||||
|
|
||||||
|
cb();
|
||||||
|
}, milliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
scheduleExecution
|
||||||
|
};
|
@ -218,7 +218,7 @@ function resetLauncher(noteId) {
|
|||||||
log.info(`Note ${noteId} is not a resettable launcher note.`);
|
log.info(`Note ${noteId} is not a resettable launcher note.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
hiddenSubtreeService.checkHiddenSubtree();
|
// the re-building deleted launchers will be done in handlers
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user