From 8cbb978401c603028ff37f3f50b692bfdaa24098 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E2=80=9EBAS8243=E2=80=9C?= <gerd.embruch@uni-hamburg.de>
Date: Tue, 30 Jul 2024 15:00:55 +0200
Subject: [PATCH] added env toggler for performance log

---
 .env.template     | 3 +++
 app.js            | 6 +++---
 utils/handleAI.js | 2 ++
 3 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/.env.template b/.env.template
index 805fc41..cb3a65b 100644
--- a/.env.template
+++ b/.env.template
@@ -30,6 +30,9 @@ SUPERADMIN_EMAIL=admin@company.local
 # won't changed if SUPERADMIN_EMAIL is already in use
 SUPERADMIN_PASSWORD=SuperSecret123!
 
+# if true timing measurements will be logged
+DEBUG_PERFORMANCE=false
+
 ##########
 # SECURITY
 ##########
diff --git a/app.js b/app.js
index 38fee1e..8fa4a04 100644
--- a/app.js
+++ b/app.js
@@ -24,7 +24,9 @@ const observer = new PerformanceObserver((list, observer) => {
         // calculate
         const measurement = performance.measure(measurementName, startName, entry.name);
         // log
-        console.info({ name: measurement.name, duration: `${measurement.duration} ms` });
+        if (process.env.DEBUG_PERFORMANCE === 'true') {
+          console.info({ name: measurement.name, duration: `${measurement.duration} ms` });
+        }
 
         // clear
         performance.clearMarks(entry.name);
@@ -36,9 +38,7 @@ const observer = new PerformanceObserver((list, observer) => {
       // clear
       performance.clearMarks(entry.name);
     }
-
     // observer.disconnect();
-
   }
 });
 observer.observe({ entryTypes: ['mark'] });
diff --git a/utils/handleAI.js b/utils/handleAI.js
index 2cdd639..d6d0eed 100644
--- a/utils/handleAI.js
+++ b/utils/handleAI.js
@@ -201,6 +201,7 @@ export const chat = async (req, res, next) => {
   result.answer = result.answer.substring(5);
   performance.mark('setSourceLocation:end');
 
+  console.log(JSON.stringify(result));
 
   // store q/a-pair in chat history
   let chat = await extendChat(req.body.chatId, [
@@ -209,6 +210,7 @@ export const chat = async (req, res, next) => {
   ]);
   performance.mark('chat:end');
 
+
   // return the answer
   return res.json({ answer: result.answer, chat });
 };
\ No newline at end of file
-- 
GitLab