Skip to content

Commit 7fc6cd0

Browse files
Merge pull request #71 from ayash911/feature/gate-debug-timers
Gate console.time/timeEnd performance logs behind DEBUG flag in data …
2 parents 416eaee + c94e9cc commit 7fc6cd0

3 files changed

Lines changed: 16 additions & 6 deletions

File tree

apps/public-api/package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
"testEnvironment": "node"
1313
},
1414
"dependencies": {
15-
"@urbackend/common": "*",
1615
"@kiroo/sdk": "^0.1.2",
1716
"@supabase/supabase-js": "^2.84.0",
17+
"@urbackend/common": "*",
1818
"bcryptjs": "^3.0.2",
1919
"bullmq": "^5.70.1",
2020
"cookie-parser": "^1.4.7",
@@ -29,6 +29,8 @@
2929
"resend": "^6.6.0",
3030
"uuid": "^9.0.1",
3131
"zod": "^4.1.13"
32+
},
33+
"devDependencies": {
34+
"jest": "^30.3.0"
3235
}
3336
}
34-

apps/public-api/src/controllers/data.controller.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ const { getConnection } = require("@urbackend/common");
55
const { getCompiledModel } = require("@urbackend/common");
66
const { QueryEngine } = require("@urbackend/common");
77
const { validateData, validateUpdateData } = require("@urbackend/common");
8+
const { performance } = require('perf_hooks');
9+
10+
const isDebug = process.env.DEBUG === 'true';
811

912
// Validate MongoDB ObjectId
1013
const isValidId = (id) => mongoose.Types.ObjectId.isValid(id);
@@ -16,7 +19,8 @@ const isDuplicateKeyError = (err) => {
1619
// INSERT DATA
1720
module.exports.insertData = async (req, res) => {
1821
try {
19-
console.time("insert data");
22+
let start;
23+
if (isDebug) start = performance.now();
2024
const { collectionName } = req.params;
2125
const project = req.project;
2226

@@ -60,7 +64,7 @@ module.exports.insertData = async (req, res) => {
6064
);
6165
}
6266

63-
console.timeEnd("insert data");
67+
if (isDebug) console.log(`[DEBUG] insert data took ${(performance.now() - start).toFixed(2)}ms`);
6468
res.status(201).json(result);
6569
} catch (err) {
6670
console.error(err);
@@ -79,7 +83,8 @@ module.exports.insertData = async (req, res) => {
7983
// GET ALL DATA
8084
module.exports.getAllData = async (req, res) => {
8185
try {
82-
console.time("getall");
86+
let start;
87+
if (isDebug) start = performance.now();
8388
const { collectionName } = req.params;
8489
const project = req.project;
8590

@@ -103,7 +108,7 @@ module.exports.getAllData = async (req, res) => {
103108
.paginate();
104109

105110
const data = await features.query.lean();
106-
console.timeEnd("getall");
111+
if (isDebug) console.log(`[DEBUG] getall took ${(performance.now() - start).toFixed(2)}ms`);
107112
res.json(data);
108113
} catch (err) {
109114
console.error(err);

package-lock.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)