mirror of
https://github.com/zadam/trilium.git
synced 2025-03-01 14:22:32 +01:00
correctly logging slow async requests
This commit is contained in:
parent
dc5304faa0
commit
a76e3f6e2d
@ -101,7 +101,12 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
|
||||
|
||||
if (resultHandler) {
|
||||
if (result && result.then) {
|
||||
result.then(actualResult => resultHandler(req, res, actualResult))
|
||||
result
|
||||
.then(actualResult => {
|
||||
resultHandler(req, res, actualResult);
|
||||
|
||||
log.request(req, res, Date.now() - start);
|
||||
})
|
||||
.catch(e => {
|
||||
log.error(`${method} ${path} threw exception: ` + e.stack);
|
||||
|
||||
@ -110,6 +115,8 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
|
||||
}
|
||||
else {
|
||||
resultHandler(req, res, result);
|
||||
|
||||
log.request(req, res, Date.now() - start);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -118,8 +125,6 @@ function route(method, path, middleware, routeHandler, resultHandler, transactio
|
||||
|
||||
res.status(500).send(e.message);
|
||||
}
|
||||
|
||||
log.request(req, res, Date.now() - start);
|
||||
});
|
||||
}
|
||||
|
||||
@ -239,7 +244,7 @@ function register(app) {
|
||||
|
||||
// group of services below are meant to be executed from outside
|
||||
route(GET, '/api/setup/status', [], setupApiRoute.getStatus, apiResultHandler);
|
||||
route(POST, '/api/setup/new-document', [auth.checkAppNotInitialized], setupApiRoute.setupNewDocument, apiResultHandler);
|
||||
route(POST, '/api/setup/new-document', [auth.checkAppNotInitialized], setupApiRoute.setupNewDocument, apiResultHandler, false);
|
||||
route(POST, '/api/setup/sync-from-server', [auth.checkAppNotInitialized], setupApiRoute.setupSyncFromServer, apiResultHandler, false);
|
||||
route(GET, '/api/setup/sync-seed', [auth.checkCredentials], setupApiRoute.getSyncSeed, apiResultHandler);
|
||||
route(POST, '/api/setup/sync-seed', [auth.checkAppNotInitialized], setupApiRoute.saveSyncSeed, apiResultHandler, false);
|
||||
|
@ -47,7 +47,7 @@ async function initDbConnection() {
|
||||
}
|
||||
|
||||
async function createInitialDatabase(username, password, theme) {
|
||||
log.info("Creating initial database ...");
|
||||
log.info("Creating database schema ...");
|
||||
|
||||
if (isDbInitialized()) {
|
||||
throw new Error("DB is already initialized");
|
||||
@ -58,6 +58,8 @@ async function createInitialDatabase(username, password, theme) {
|
||||
|
||||
let rootNote;
|
||||
|
||||
log.info("Creating root note ...");
|
||||
|
||||
sql.transactional(() => {
|
||||
sql.executeScript(schema);
|
||||
|
||||
@ -82,11 +84,15 @@ async function createInitialDatabase(username, password, theme) {
|
||||
}).save();
|
||||
});
|
||||
|
||||
log.info("Importing demo content ...");
|
||||
|
||||
const dummyTaskContext = new TaskContext("initial-demo-import", 'import', false);
|
||||
|
||||
const zipImportService = require("./import/zip");
|
||||
await zipImportService.importZip(dummyTaskContext, demoFile, rootNote);
|
||||
|
||||
log.info("Initializing options ...");
|
||||
|
||||
sql.transactional(() => {
|
||||
const startNoteId = sql.getValue("SELECT noteId FROM branches WHERE parentNoteId = 'root' AND isDeleted = 0 ORDER BY notePosition");
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user