From 06ebcc210e47a5e97386d7af9d1253889f31406d Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Sat, 11 Jan 2025 00:54:10 +0100 Subject: [PATCH] refactor(backend_log): use async readFile using synchronous functions on the backend is not recommended, as it is "blocking the event loop", i.e. no other tasks get executed/processed, while the file is being read --- src/routes/api/backend_log.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/routes/api/backend_log.ts b/src/routes/api/backend_log.ts index f57886242..ae2fec492 100644 --- a/src/routes/api/backend_log.ts +++ b/src/routes/api/backend_log.ts @@ -1,15 +1,15 @@ "use strict"; -import fs from "fs"; +import { readFile } from "fs/promises"; import dateUtils from "../../services/date_utils.js"; import dataDir from "../../services/data_dir.js"; const { LOG_DIR } = dataDir; -function getBackendLog() { +async function getBackendLog() { const file = `${LOG_DIR}/trilium-${dateUtils.localNowDate()}.log`; try { - return fs.readFileSync(file, "utf8"); + return await readFile(file, "utf8"); } catch (e) { // most probably the log file does not exist yet - https://github.com/zadam/trilium/issues/1977 return "";