mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
performance monitoring on frontend in dev environment
This commit is contained in:
parent
81207f3d27
commit
5d500de527
@ -13,12 +13,17 @@ import utils from '../services/utils.js';
|
|||||||
*/
|
*/
|
||||||
export default class Component {
|
export default class Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.componentId = `comp-` + utils.randomString(8);
|
this.componentId = `comp-` + this.sanitizedClassName + '-' + utils.randomString(8);
|
||||||
/** @type Component[] */
|
/** @type Component[] */
|
||||||
this.children = [];
|
this.children = [];
|
||||||
this.initialized = Promise.resolve();
|
this.initialized = Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get sanitizedClassName() {
|
||||||
|
// webpack mangles names and sometimes uses unsafe characters
|
||||||
|
return this.constructor.name.replace(/[^A-Z0-9]/ig, "_");
|
||||||
|
}
|
||||||
|
|
||||||
setParent(parent) {
|
setParent(parent) {
|
||||||
/** @type Component */
|
/** @type Component */
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@ -76,7 +81,17 @@ export default class Component {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fun.call(this, data);
|
const startTime = Date.now();
|
||||||
|
|
||||||
|
const promise = fun.call(this, data);
|
||||||
|
|
||||||
|
const took = Date.now() - startTime;
|
||||||
|
|
||||||
|
if (glob.isDev && took > 20) { // measuring only sync handlers
|
||||||
|
console.log(`Call to ${fun.name} in ${this.componentId} took ${took}ms`);
|
||||||
|
}
|
||||||
|
|
||||||
|
await promise;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -197,8 +197,20 @@ function executeScript(query) {
|
|||||||
|
|
||||||
function wrap(query, func) {
|
function wrap(query, func) {
|
||||||
const startTimestamp = Date.now();
|
const startTimestamp = Date.now();
|
||||||
|
let result;
|
||||||
|
|
||||||
const result = func(stmt(query));
|
try {
|
||||||
|
result = func(stmt(query));
|
||||||
|
}
|
||||||
|
catch (e) {
|
||||||
|
if (e.message.includes("The database connection is not open")) {
|
||||||
|
// this often happens on killing the app which puts these alerts in front of user
|
||||||
|
// in these cases error should be simply ignored.
|
||||||
|
console.log(e.message);
|
||||||
|
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const milliseconds = Date.now() - startTimestamp;
|
const milliseconds = Date.now() - startTimestamp;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user