1- const { randomUUID } = require ( "crypto" ) ;
21const { sanitize } = require ( "@urbackend/common" ) ;
32const mongoose = require ( 'mongoose' ) ;
43const { Project } = require ( "@urbackend/common" ) ;
54const { getConnection } = require ( "@urbackend/common" ) ;
65const { getCompiledModel } = require ( "@urbackend/common" ) ;
76const { QueryEngine} = require ( "@urbackend/common" ) ;
87const { validateData, validateUpdateData } = require ( "@urbackend/common" ) ;
8+ const { performance } = require ( 'perf_hooks' ) ;
9+
10+ const isDebug = process . env . DEBUG === 'true' ;
911
1012// Validate MongoDB ObjectId
1113const isValidId = ( id ) => mongoose . Types . ObjectId . isValid ( id ) ;
1214
1315// INSERT DATA
1416module . exports . insertData = async ( req , res ) => {
1517 try {
16- const isDebug = process . env . DEBUG === 'true' ;
17- const timerLabel = isDebug ? `insert data - ${ randomUUID ( ) } ` : null ;
18- if ( isDebug ) console . time ( timerLabel ) ;
18+ let start ;
19+ if ( isDebug ) start = performance . now ( ) ;
1920 const { collectionName } = req . params ;
2021 const project = req . project ;
2122
@@ -51,7 +52,7 @@ module.exports.insertData = async (req, res) => {
5152 ) ;
5253 }
5354
54- if ( isDebug ) console . timeEnd ( timerLabel ) ;
55+ if ( isDebug ) console . log ( `[DEBUG] insert data took ${ ( performance . now ( ) - start ) . toFixed ( 2 ) } ms` ) ;
5556 res . status ( 201 ) . json ( result ) ;
5657 } catch ( err ) {
5758 console . error ( err ) ;
@@ -62,9 +63,8 @@ module.exports.insertData = async (req, res) => {
6263// GET ALL DATA
6364module . exports . getAllData = async ( req , res ) => {
6465 try {
65- const isDebug = process . env . DEBUG === 'true' ;
66- const timerLabel = isDebug ? `getall - ${ randomUUID ( ) } ` : null ;
67- if ( isDebug ) console . time ( timerLabel ) ;
66+ let start ;
67+ if ( isDebug ) start = performance . now ( ) ;
6868 const { collectionName } = req . params ;
6969 const project = req . project ;
7070
@@ -80,7 +80,7 @@ module.exports.getAllData = async (req, res) => {
8080 . paginate ( ) ;
8181
8282 const data = await features . query . lean ( ) ;
83- if ( isDebug ) console . timeEnd ( timerLabel ) ;
83+ if ( isDebug ) console . log ( `[DEBUG] getall took ${ ( performance . now ( ) - start ) . toFixed ( 2 ) } ms` ) ;
8484 res . json ( data ) ;
8585 } catch ( err ) {
8686 console . error ( err ) ;
0 commit comments