mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
messaging now uses mutex so each component processes only single message at each time
This commit is contained in:
parent
1d2fc773c2
commit
81a54cd4a0
6
package-lock.json
generated
6
package-lock.json
generated
@ -8826,9 +8826,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"semver": {
|
"semver": {
|
||||||
"version": "7.1.2",
|
"version": "7.1.3",
|
||||||
"resolved": "https://registry.npmjs.org/semver/-/semver-7.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/semver/-/semver-7.1.3.tgz",
|
||||||
"integrity": "sha512-BJs9T/H8sEVHbeigqzIEo57Iu/3DG6c4QoqTfbQB3BPA4zgzAomh/Fk9E7QtjWQ8mx2dgA9YCfSF4y9k9bHNpQ=="
|
"integrity": "sha512-ekM0zfiA9SCBlsKa2X1hxyxiI4L3B6EbVJkkdgQXnSEEaHlGdvyodMruTiulSRWMMB4NeIuYNMC9rTKTz97GxA=="
|
||||||
},
|
},
|
||||||
"semver-compare": {
|
"semver-compare": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -61,7 +61,7 @@
|
|||||||
"rimraf": "3.0.2",
|
"rimraf": "3.0.2",
|
||||||
"sanitize-filename": "1.6.3",
|
"sanitize-filename": "1.6.3",
|
||||||
"sax": "1.2.4",
|
"sax": "1.2.4",
|
||||||
"semver": "7.1.2",
|
"semver": "7.1.3",
|
||||||
"serve-favicon": "2.5.0",
|
"serve-favicon": "2.5.0",
|
||||||
"session-file-store": "1.4.0",
|
"session-file-store": "1.4.0",
|
||||||
"simple-node-logger": "18.12.24",
|
"simple-node-logger": "18.12.24",
|
||||||
|
29
src/public/javascripts/services/mutex.js
Normal file
29
src/public/javascripts/services/mutex.js
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
export default class Mutex {
|
||||||
|
constructor() {
|
||||||
|
this.queue = [];
|
||||||
|
this.pending = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
isLocked() {
|
||||||
|
return this.pending;
|
||||||
|
}
|
||||||
|
|
||||||
|
acquire() {
|
||||||
|
const ticket = new Promise(resolve => this.queue.push(resolve));
|
||||||
|
|
||||||
|
if (!this.pending) {
|
||||||
|
this.dispatchNext();
|
||||||
|
}
|
||||||
|
|
||||||
|
return ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
dispatchNext() {
|
||||||
|
if (this.queue.length > 0) {
|
||||||
|
this.pending = true;
|
||||||
|
this.queue.shift()(this.dispatchNext.bind(this));
|
||||||
|
} else {
|
||||||
|
this.pending = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
import utils from '../services/utils.js';
|
import utils from '../services/utils.js';
|
||||||
|
import Mutex from "../services/mutex.js";
|
||||||
|
|
||||||
export default class Component {
|
export default class Component {
|
||||||
/** @param {AppContext} appContext */
|
/** @param {AppContext} appContext */
|
||||||
@ -11,6 +12,7 @@ export default class Component {
|
|||||||
/** @type Component[] */
|
/** @type Component[] */
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.initialized = Promise.resolve();
|
this.initialized = Promise.resolve();
|
||||||
|
this.mutex = new Mutex();
|
||||||
}
|
}
|
||||||
|
|
||||||
async eventReceived(name, data, sync = false) {
|
async eventReceived(name, data, sync = false) {
|
||||||
@ -23,8 +25,19 @@ export default class Component {
|
|||||||
const start = Date.now();
|
const start = Date.now();
|
||||||
|
|
||||||
if (typeof fun === 'function') {
|
if (typeof fun === 'function') {
|
||||||
|
let release;
|
||||||
|
|
||||||
|
try {
|
||||||
|
release = await this.mutex.acquire();
|
||||||
|
|
||||||
propagateToChildren = await fun.call(this, data) !== false;
|
propagateToChildren = await fun.call(this, data) !== false;
|
||||||
}
|
}
|
||||||
|
finally {
|
||||||
|
if (release) {
|
||||||
|
release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const end = Date.now();
|
const end = Date.now();
|
||||||
|
|
||||||
@ -46,12 +59,14 @@ export default class Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async triggerChildren(name, data, sync = false) {
|
async triggerChildren(name, data, sync = false) {
|
||||||
|
const promises = [];
|
||||||
|
|
||||||
for (const child of this.children) {
|
for (const child of this.children) {
|
||||||
let promise = child.eventReceived(name, data, sync);
|
promises.push(child.eventReceived(name, data, sync));
|
||||||
|
}
|
||||||
|
|
||||||
if (sync) {
|
if (sync) {
|
||||||
await promise;
|
await Promise.all(promises);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -372,7 +372,7 @@ export default class NoteTreeWidget extends TabAwareWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async updateNode(node) {
|
async updateNode(node) {
|
||||||
const note = await treeCache.getNote(node.data.noteId);
|
const note = treeCache.getNoteFromCache(node.data.noteId);
|
||||||
const branch = treeCache.getBranch(node.data.branchId);
|
const branch = treeCache.getBranch(node.data.branchId);
|
||||||
|
|
||||||
node.data.isProtected = note.isProtected;
|
node.data.isProtected = note.isProtected;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user